void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0.3, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set current material glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuseColor); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specularColor); // Place camera and light glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(100,50,50, 0, 0, 0, 0, 1, 0); // No manual control but better place from the start glLoadMatrixd(getCameraMatrix()); glLightfv(GL_LIGHT0, GL_POSITION, light_position); // After camera matrix - camera independent! // Render the scene! renderGround(); renderTerrain(); // Swap front- and backbuffers glutSwapBuffers(); }
static void RenderTerrain() { if(gTerrainData) { renderTerrainTriangles(*gTerrainData, gTouchedTris.size(), &gTouchedTris[0]); renderTerrain(*gTerrainData); } }
void display() { // This function is called whenever it is time to render // a new frame; due to the idle()-function below, this // function will get called several times per second // Clear framebuffer & zbuffer glClearColor(0.3, 0.4, 0.5, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Setup projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90, 1, 0.01, 500); // Setup object matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Enable textures. glEnable(GL_TEXTURE_2D); // Fix the SkyBox to the camera. renderSkyBox(); glPushAttrib(GL_ALL_ATTRIB_BITS); // Position light 0 GLfloat light_position[] = { 0.0, 1.0, 0.0, 0.0 }; // Directional from above glLightfv(GL_LIGHT0, GL_POSITION, light_position); // Set default material properties GLfloat mat_shininess[] = { 50.0 }; GLfloat mat_diffuseColor[] = { 1.0, 1.0, 1.0, 0.5 }; glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuseColor); // Enable lighting and light 0 glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); // Enable Z-buffering glEnable(GL_DEPTH_TEST); // Enable Gouraud shading glShadeModel(GL_SMOOTH); // Enable backface culling glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glPushMatrix(); // Enable texturing glEnable(GL_TEXTURE_2D); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); // Render the terrain renderTerrain(); // Render some random props (like trees) renderProps(); // Check if the helicopter hits the ground (if so, exit!) handleCollisions(); // Update the camera (and helicopter) position updatePosition(); // Render the helicopter renderHelicopter(); glPopAttrib(); // Swap front- and backbuffers glutSwapBuffers(); }
//-------------------------------------------------------------------- // render the view void Landscape::appViewDraw() { mgPoint3 renderEyePt(m_eyePt); if (m_mapView) renderEyePt.y = MAPVIEW_HEIGHT; // draw the sky mgDisplay->setFrontAndBack(0.25, 16384); mgMatrix4 identity; m_eyeMatrix.loadIdentity(); if (m_mapView) { m_eyeMatrix.rotateZDeg(m_eyeRotZ); m_eyeMatrix.rotateYDeg(m_eyeRotY); m_eyeMatrix.rotateXDeg(-90); } else { m_eyeMatrix.rotateZDeg(m_eyeRotZ); m_eyeMatrix.rotateYDeg(m_eyeRotY); m_eyeMatrix.rotateXDeg(m_eyeRotX); } mgDisplay->setEyeMatrix(m_eyeMatrix); mgDisplay->setEyePt(mgPoint3(0,0,0)); mgDisplay->setModelTransform(identity); mgDisplay->setCulling(true); m_sky->setFogColor(m_fogColor); m_sky->setFogHeight(m_fogBotHeight - renderEyePt.y, m_fogTopHeight - renderEyePt.y); m_sky->setFogDist(HORIZON_SIZE, m_fogMaxDist); m_sky->render(); // reset state after any changes in sky render mgDisplay->setLightDir(m_lightDir.x, m_lightDir.y, m_lightDir.z); mgDisplay->setMatColor(1.0, 1.0, 1.0); mgDisplay->setLightColor(m_lightColor.x, m_lightColor.y, m_lightColor.z); mgDisplay->setLightAmbient(m_lightAmbient.x, m_lightAmbient.y, m_lightAmbient.z); mgDisplay->setTransparent(false); mgDisplay->setEyeMatrix(m_eyeMatrix); mgDisplay->setEyePt(mgPoint3(0,0,0)); // we use relative coordinates in render if (mgDisplay->getDepthBits() == 32) { mgDisplay->setFrontAndBack(0.25, 65536*4); renderTerrain(); } else if (mgDisplay->getDepthBits() >= 24) { mgDisplay->setFrontAndBack(256, 65536*4); renderTerrain(); mgDisplay->setFrontAndBack(0.25, 256); mgDisplay->clearBuffer(MG_DEPTH_BUFFER); renderTerrain(); } else { mgDisplay->setFrontAndBack(4096, 65536*4); renderTerrain(); mgDisplay->setFrontAndBack(32, 4096); mgDisplay->clearBuffer(MG_DEPTH_BUFFER); renderTerrain(); mgDisplay->setFrontAndBack(0.25, 32); mgDisplay->clearBuffer(MG_DEPTH_BUFFER); renderTerrain(); } }