// Render the cube and sphere void DrawObjects(void) { // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Translate the whole scene out and into view glTranslatef(-80.0f, 0.0f, -300.0f); // Initialize the names stack glInitNames(); glPushName(0); // Set material color, Yellow // Cube glRGB(255, 255, 0); glLoadName(CUBE); glPassThrough((GLfloat)CUBE); glutSolidCube(75.0f); // Draw Sphere glRGB(128,0,0); glTranslatef(130.0f, 0.0f, 0.0f); glLoadName(SPHERE); glPassThrough((GLfloat)SPHERE); glutSolidSphere(50.0f, 15, 15); // Restore the matrix state glPopMatrix(); // Modelview matrix }
void CGWorldTriangleFan::DumpToGL() const { glBegin(GL_TRIANGLE_FAN); glRGB(GetRValue(m_crColor),GetGValue(m_crColor),GetBValue(m_crColor)); for (int i=0; i<m_iNumVertices; i++) { glNormal3f(m_pVertices[i].m_fNormal[0],m_pVertices[i].m_fNormal[1],m_pVertices[i].m_fNormal[2]); glVertex3f(m_pVertices[i].m_fPos[0],m_pVertices[i].m_fPos[1],m_pVertices[i].m_fPos[2]); } glEnd(); }
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(); }
void CGWorldOpenGL::CompileLists() { //Our compile strategy is to split the geometry into different //pieces so that we can turn on and off sections by simply rendering //the pieces that we want. /*TEST GEOMETRY glRGB(255,0,0); glBegin(GL_LINES); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(0.0f,100.0f,-100.0f); glEnd(); glBegin(GL_LINES); glVertex3f(0.0f,100.0f,-100.0f); glVertex3f(50.0f,150.0f,-200.0f); glEnd(); glRGB(0,0,255); glBegin(GL_TRIANGLES); glVertex3f(30.f,30.f,300.f); glVertex3f(30.f,40.f,300.f); glVertex3f(40.f,40.f,300.f); glEnd(); glRGB(0,0,255); glBegin(GL_TRIANGLES); glVertex3f(60.f,60.f,-1000.f); glVertex3f(60.f,70.f,-1000.f); glVertex3f(70.f,70.f,-1000.f); glEnd(); glEndList(); */ //Start with the lines and rectangles which define the underground stuff glNewList(MYLIST_CAVEGEOMETRY,GL_COMPILE); int iLineCount=m_LineArray.GetSize(); for (int i=0; i<iLineCount; i++) { const CGWorldOpenGLLine& line=m_LineArray.GetAt(i); if (line.crColor!=CLOSURE_RGB) { line.DumpToGL(); } } int iTriangleGroupCount=m_TriangleGroupArray.GetSize(); for (i=0; i<iTriangleGroupCount; i++) { CGWorldTriangleGroup const * pGroup=m_TriangleGroupArray.GetAt(i); pGroup->DumpToGL(); } glEndList(); glNewList(MYLIST_CLOSUREERRORS,GL_COMPILE); for (i=0; i<iLineCount; i++) { const CGWorldOpenGLLine& line=m_LineArray.GetAt(i); glEnable(GL_LINE_STIPPLE); glLineStipple(5,0x5555); //dashed lines 5 pixels long glRGB(255,0,0); if (line.crColor==CLOSURE_RGB) { line.DumpToGL(); } glDisable(GL_LINE_STIPPLE); } glEndList(); glNewList(MYLIST_WIREFRAMEMODE,GL_COMPILE); iLineCount=m_WireframeLineArray.GetSize(); for (i=0; i<iLineCount; i++) { const CGWorldOpenGLLine& line=m_WireframeLineArray.GetAt(i); line.DumpToGL(); } glEndList(); }
// Called to draw scene void RenderScene(void) { float fZ,bZ; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); fZ = 100.0f; bZ = -100.0f; // Save the matrix state and do the rotations glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(0.0f, 0.0f, -300.0f); glRotatef(xRot++, 0.0f, 0.0f, 0.0f); glRotatef(yRot++, 0.0f, 1.0f, 0.0f); printf("abc:%f,%f\n", xRot, yRot); // Set material color, Red glRGB(192, 0, 0); // Front Face /////////////////////////////////// glBegin(GL_QUADS); // Pointing straight out Z glNormal3f(0.0f, 0.0f, 1.0f); // Left Panel glVertex3f(-50.0f, 50.0f, fZ); glVertex3f(-50.0f, -50.0f, fZ); glVertex3f(-35.0f, -50.0f, fZ); glVertex3f(-35.0f,50.0f,fZ); // Right Panel glVertex3f(50.0f, 50.0f, fZ); glVertex3f(35.0f, 50.0f, fZ); glVertex3f(35.0f, -50.0f, fZ); glVertex3f(50.0f,-50.0f,fZ); // Top Panel glVertex3f(-35.0f, 50.0f, fZ); glVertex3f(-35.0f, 35.0f, fZ); glVertex3f(35.0f, 35.0f, fZ); glVertex3f(35.0f, 50.0f,fZ); // Bottom Panel glVertex3f(-35.0f, -35.0f, fZ); glVertex3f(-35.0f, -50.0f, fZ); glVertex3f(35.0f, -50.0f, fZ); glVertex3f(35.0f, -35.0f,fZ); // Top length section //////////////////////////// // Normal points up Y axis glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(-50.0f, 50.0f, fZ); glVertex3f(50.0f, 50.0f, fZ); glVertex3f(50.0f, 50.0f, bZ); glVertex3f(-50.0f,50.0f,bZ); // Bottom section glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(-50.0f, -50.0f, fZ); glVertex3f(-50.0f, -50.0f, bZ); glVertex3f(50.0f, -50.0f, bZ); glVertex3f(50.0f, -50.0f, fZ); // Left section glNormal3f(1.0f, 0.0f, 0.0f); glVertex3f(50.0f, 50.0f, fZ); glVertex3f(50.0f, -50.0f, fZ); glVertex3f(50.0f, -50.0f, bZ); glVertex3f(50.0f, 50.0f, bZ); // Right Section glNormal3f(-1.0f, 0.0f, 0.0f); glVertex3f(-50.0f, 50.0f, fZ); glVertex3f(-50.0f, 50.0f, bZ); glVertex3f(-50.0f, -50.0f, bZ); glVertex3f(-50.0f, -50.0f, fZ); glEnd(); glFrontFace(GL_CW); // clock-wise polygons face out // Set material color, Red glBegin(GL_QUADS); // Back section // Pointing straight out Z glNormal3f(0.0f, 0.0f, -1.0f); // Left Panel glVertex3f(-50.0f, 50.0f, bZ); glVertex3f(-50.0f, -50.0f, bZ); glVertex3f(-35.0f, -50.0f, bZ); glVertex3f(-35.0f,50.0f,bZ); // Right Panel glVertex3f(50.0f, 50.0f, bZ); glVertex3f(35.0f, 50.0f, bZ); glVertex3f(35.0f, -50.0f, bZ); glVertex3f(50.0f,-50.0f,bZ); // Top Panel glVertex3f(-35.0f, 50.0f, bZ); glVertex3f(-35.0f, 35.0f, bZ); glVertex3f(35.0f, 35.0f, bZ); glVertex3f(35.0f, 50.0f,bZ); // Bottom Panel glVertex3f(-35.0f, -35.0f, bZ); glVertex3f(-35.0f, -50.0f, bZ); glVertex3f(35.0f, -50.0f, bZ); glVertex3f(35.0f, -35.0f,bZ); // Insides ///////////////////////////// glRGB(192, 192, 192); // Normal points up Y axis glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(-35.0f, 35.0f, fZ); glVertex3f(35.0f, 35.0f, fZ); glVertex3f(35.0f, 35.0f, bZ); glVertex3f(-35.0f,35.0f,bZ); // Bottom section glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(-35.0f, -35.0f, fZ); glVertex3f(-35.0f, -35.0f, bZ); glVertex3f(35.0f, -35.0f, bZ); glVertex3f(35.0f, -35.0f, fZ); // Left section glNormal3f(1.0f, 0.0f, 0.0f); glVertex3f(-35.0f, 35.0f, fZ); glVertex3f(-35.0f, 35.0f, bZ); glVertex3f(-35.0f, -35.0f, bZ); glVertex3f(-35.0f, -35.0f, fZ); // Right Section glNormal3f(-1.0f, 0.0f, 0.0f); glVertex3f(35.0f, 35.0f, fZ); glVertex3f(35.0f, -35.0f, fZ); glVertex3f(35.0f, -35.0f, bZ); glVertex3f(35.0f, 35.0f, bZ); glEnd(); glFrontFace(GL_CCW); // Counter clock-wise polygons face out // Restore the matrix state glPopMatrix(); // Modelview matrix // Flush drawing commands glFlush(); }