static void DrawScene(void) { int i; glEnable(GL_LIGHTING); for (i = 0; i < NUM_CYLINDERS; i++) { DrawCylinder(&Cylinders[i]); } glDisable(GL_LIGHTING); if (1) DrawLightSource(); /* ground plane */ if (1) { GLfloat k = 10.0, g = GroundY; CheckError(__LINE__); glPushMatrix(); glColor3fv(GroundColor); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, GroundColor); glNormal3f(0, 1, 0); glBegin(GL_POLYGON); glVertex3f(-k, g, -k); glVertex3f( k, g, -k); glVertex3f( k, g, k); glVertex3f(-k, g, k); glEnd(); glPopMatrix(); } CheckError(__LINE__); }
void RedrawFunc( void ) { // all time in milliseconds int elapsedTime = glutGet( GLUT_ELAPSED_TIME ); static int prevElapsedTime = 0; static float timeAccum = 0.0; int deltaTime = elapsedTime - prevElapsedTime; vec3_t lightPosition = { 0.0f, 0.0f, 60.0f }; prevElapsedTime = elapsedTime; glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDepthFunc( GL_LEQUAL ); glEnable( GL_DEPTH_TEST ); if( drawLighting ) { SetLight( lightPosition ); } if( drawBaseTexture ) { glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, BASE_TEXTURE ); // glBindTexture( GL_TEXTURE_2D, NORMAL_TEXTURE ); } else { glDisable( GL_TEXTURE_2D ); } if( drawWireFrame ) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glCallList( WIRE_LIST ); } else { glCallList( QUAD_LIST ); } glDisable( GL_TEXTURE_2D ); glDisable( GL_LIGHTING ); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if( drawNormals ) { glColor3f( 0.0f, 1.0f, 0.0f ); glCallList( NORMAL_LIST ); glColor3f( 1.0f, 1.0f, 1.0f ); } DrawLightSource( lightPosition, 1.0f, 1.0f, 1.0f ); DrawStatus(); glutSwapBuffers(); glFinish(); }