void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glColor3f(1.0,0.0,0.0); kostka(); glPopMatrix(); float points[3][3] ={{-400.0f, -64.0, 200.0f},{400.0f, -64.0, 200.0f},{400.0f, -15.0, -200.0f}}; float lightPos[] = { 0.0, 150.0, 50.0, 1.0 }; MakeShadowMatrix(points, lightPos, shadowMat); glPushAttrib(GL_LIGHTING_BIT); glDisable(GL_LIGHTING); glPushMatrix(); glMultMatrixf((float *)shadowMat); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glColor3f(0.0,0.0,0.0); kostka2(); glPopMatrix(); glBegin(GL_POLYGON); glRGB(0,128,0); glVertex3f(-400.0f, -65.0, 200.0f); glVertex3f(400.0f, -65.0, 200.0f); glRGB(0,255,0); glVertex3f(400.0f, -15.0, -200.0f); glVertex3f(-400.0f, -15.0, -200.0f); glEnd(); glPopAttrib(); glFlush (); glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { GLfloat cubeXform[4][4]; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); glPushMatrix(); // Draw plane that the cube rests on glDisable(GL_LIGHTING); if(nStep == 5) { glColor3ub(255,255,255); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, textures[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-100.0f, -25.3f, -100.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-100.0f, -25.3f, 100.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(100.0f, -25.3f, 100.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(100.0f, -25.3f, -100.0f); glEnd(); } else { glColor3f(0.0f, 0.0f, 0.90f); // Blue glBegin(GL_QUADS); glVertex3f(-100.0f, -25.3f, -100.0f); glVertex3f(-100.0f, -25.3f, 100.0f); glVertex3f(100.0f, -25.3f, 100.0f); glVertex3f(100.0f, -25.3f, -100.0f); glEnd(); } // Set drawing color to Red glColor3f(1.0f, 0.0f, 0.0f); // Enable, disable lighting if(nStep > 2) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_COLOR_MATERIAL); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT, GL_SPECULAR,lightSpecular); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor); glMateriali(GL_FRONT, GL_SHININESS,128); } // Move the cube slightly forward and to the left glTranslatef(-10.0f, 0.0f, 10.0f); switch(nStep) { // Just draw the wire framed cube case 0: glutWireCube(50.0f); break; // Same wire cube with hidden line removal simulated case 1: // Front Face (before rotation) glBegin(GL_LINES); glVertex3f(25.0f,25.0f,25.0f); glVertex3f(25.0f,-25.0f,25.0f); glVertex3f(25.0f,-25.0f,25.0f); glVertex3f(-25.0f,-25.0f,25.0f); glVertex3f(-25.0f,-25.0f,25.0f); glVertex3f(-25.0f,25.0f,25.0f); glVertex3f(-25.0f,25.0f,25.0f); glVertex3f(25.0f,25.0f,25.0f); glEnd(); // Top of cube glBegin(GL_LINES); // Front Face glVertex3f(25.0f,25.0f,25.0f); glVertex3f(25.0f,25.0f,-25.0f); glVertex3f(25.0f,25.0f,-25.0f); glVertex3f(-25.0f,25.0f,-25.0f); glVertex3f(-25.0f,25.0f,-25.0f); glVertex3f(-25.0f,25.0f,25.0f); glVertex3f(-25.0f,25.0f,25.0f); glVertex3f(25.0f,25.0f,25.0f); glEnd(); // Last two segments for effect glBegin(GL_LINES); glVertex3f(25.0f,25.0f,-25.0f); glVertex3f(25.0f,-25.0f,-25.0f); glVertex3f(25.0f,-25.0f,-25.0f); glVertex3f(25.0f,-25.0f,25.0f); glEnd(); break; // Uniform colored surface, looks 2D and goofey case 2: glutSolidCube(50.0f); break; case 3: glutSolidCube(50.0f); break; // Draw a shadow with some lighting case 4: glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) cubeXform); glutSolidCube(50.0f); glPopMatrix(); // Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING); glPushMatrix(); MakeShadowMatrix(ground, lightpos, cubeXform); glMultMatrixf((GLfloat *)cubeXform); glTranslatef(-10.0f, 0.0f, 10.0f); // Set drawing color to Black glColor3f(0.0f, 0.0f, 0.0f); glutSolidCube(50.0f); break; case 5: glColor3ub(255,255,255); glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) cubeXform); // Front Face (before rotation) glBindTexture(GL_TEXTURE_2D, textures[1]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3f(25.0f,25.0f,25.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(25.0f,-25.0f,25.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-25.0f,-25.0f,25.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-25.0f,25.0f,25.0f); glEnd(); // Top of cube glBindTexture(GL_TEXTURE_2D, textures[2]); glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(25.0f,25.0f,25.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(25.0f,25.0f,-25.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-25.0f,25.0f,-25.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-25.0f,25.0f,25.0f); glEnd(); // Last two segments for effect glBindTexture(GL_TEXTURE_2D, textures[3]); glBegin(GL_QUADS); glTexCoord2f(1.0f, 1.0f); glVertex3f(25.0f,25.0f,-25.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(25.0f,-25.0f,-25.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(25.0f,-25.0f,25.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(25.0f,25.0f,25.0f); glEnd(); glPopMatrix(); // Disable lighting, we'll just draw the shadow as black glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPushMatrix(); MakeShadowMatrix(ground, lightpos, cubeXform); glMultMatrixf((GLfloat *)cubeXform); glTranslatef(-10.0f, 0.0f, 10.0f); // Set drawing color to Black glColor3f(0.0f, 0.0f, 0.0f); glutSolidCube(50.0f); break; } glPopMatrix(); // Flush drawing commands glutSwapBuffers(); }