Jump to content

  • Log In with Google      Sign In   
  • Create Account

New to open gl and having problems!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 rpcsite   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 June 2001 - 11:44 AM

I''m trying to write a program in opengl. The program starts off with a plane (the triangle in between the two red strips) about to takeoff. Left or right clicking starts the plane. A left click tells it to take off to the left, a right click to the right. Here are the problems I''m having --> On the left-click version, a picture of the plane freezes at the top after take off. Neither lets the plane travel to the left or right after takeoff. Also, I wanted to put fire coming from the center of the base of the triangle, I tried to do that earlier, but it wouldn''t let me (I tried drawing lines that would move with the triangle''s position in an orange color coming from the base). Two last things, how would I make a clean rotation of the triangle instead of just a jumpy one after takeoff and is there any reason I would be having trouble using classes in open gl? Anyways, here''s my code so far: // please don''t mind the sloppiness!!! #include #include #include #include #include GLubyte quit = 0; GLshort top = 40; GLshort turn = 0; GLshort y_or_x = 0; GLfloat speed = 0.0f; GLfloat o_speed = 0.0f; GLfloat engine_step = .2; GLfloat Tx1 = -5.0f; GLfloat Ty1 = -40.0f; GLfloat Tx2 = 0.0f; GLfloat Ty2 = -30.0f; GLfloat Tx3 = 5.0f; GLfloat Ty3 = -40.0f; GLfloat T2x1 = -10.0f; GLfloat T2y1 = 0.0f; GLfloat T2x2 = 0.0f; GLfloat T2y2 = 5.0f; GLfloat T2x3 = 0.0f; GLfloat T2y3 = -5.0f; GLfloat T3x1 = 10.0f; GLfloat T3y1 = 0.0f; GLfloat T3x2 = 0.0f; GLfloat T3y2 = 5.0f; GLfloat T3x3 = 0.0f; GLfloat T3y3 = -5.0f; // Called to draw scene void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0f, 0.0f, 0.0f); glTranslatef(-10.0f,0.0f, 0.0f); glBegin(GL_QUADS); glVertex2f(-2.0f, 40.0f); glVertex2f(-2.0f,-40.0f); glVertex2f(2.0f, -40.0f); glVertex2f(2.0f, 40.0f); glEnd(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(10.0f,0.0f, 0.0f); glBegin(GL_QUADS); glVertex2f(-2.0f, 40.0f); glVertex2f(-2.0f, -40.0f); glVertex2f(2.0f, -40.0f); glVertex2f(2.0f, 40.0f); glEnd(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if(turn == 0) { glBegin(GL_TRIANGLES); glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(Tx1, Ty1); glVertex2f(Tx2, Ty2); glVertex2f(Tx3, Ty3); glEnd(); }; if(turn == 1 && Ty1 > top) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); y_or_x++; glTranslatef(0.0f, 45.0f, 0.0f); glBegin(GL_TRIANGLES); glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(T2x1, T2y1); glVertex2f(T2x2, T2y2); glVertex2f(T2x3, T2y3); glEnd(); }; if(turn == 2 && Ty1 > top) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); y_or_x++; glTranslatef(0.0f, 45.0f, 0.0f); glBegin(GL_TRIANGLES); glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(T3x1, T3y1); glVertex2f(T3x2, T3y2); glVertex2f(T3x3, T3y3); glEnd(); }; if(turn == 1 || turn == 2 && Ty1 < top) { glBegin(GL_TRIANGLES); glColor3f(0.0f, 0.0f, 1.0f); glVertex2f(Tx1, Ty1); glVertex2f(Tx2, Ty2); glVertex2f(Tx3, Ty3); glEnd(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }; glPushMatrix(); // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); } // This function does any needed initialization on the rendering // context. void SetupRC() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set color shading model to flat glShadeModel(GL_FLAT); // Clock wise wound polygons are front facing, this is reversed // because we are using triangle fans glFrontFace(GL_CW); } void MouseHandler(int button, int state, int x, int y) { if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { MessageBeep(-1); turn = 1; }; if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { MessageBeep(-1); turn = 2; }; } void SpecialKeys(int key, int x, int y) { glutPostRedisplay(); } void TimerFunction(int value) { if(y_or_x == 0 && Ty1 < top && turn == 1 || turn == 2) { Ty1 += speed; Ty2 += speed; Ty3 += speed; speed += .02; }; if(turn == 1 && y_or_x == 0 && Ty1 >= top) { T2x1 -= o_speed; T2x2 -= o_speed; T2x3 -= o_speed; o_speed -= .02; }; if(turn == 2 && y_or_x == 1 && Ty1 >= top) { T3x1 += o_speed; T3x2 += o_speed; T3x3 += o_speed; o_speed += .02; }; glutPostRedisplay(); glutTimerFunc(33, TimerFunction, 1); } void ChangeSize(int w, int h) { GLfloat nRange = 100.0f; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Control Tower, Takeoff"); glutDisplayFunc(RenderScene); glutTimerFunc(33, TimerFunction, 1); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutMouseFunc(MouseHandler); SetupRC(); glutMainLoop(); return 0; } PS: I''d like to have the program end when the user hits the Esc key! Thanks A lot!!! Visit rpcsite.com, opening fall of 2001.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS