void RenderManager::RenderAll() // Iterates through all the items in the render list // translates the render context to the object's base position then // renders the object. // Objects are drawn in order, opaque first then transparent, with transparent objects // further away being drawn first { BuildProjectionMatrix(); PrepareLights(); viewMatrixMade = false; DrawSkyBox(); DrawTerrain(); std::vector<int>::iterator vit; if (opaqueRenderList.size() > 0) { for (vit = opaqueRenderList.begin(); vit != opaqueRenderList.end(); vit++) { if (!DrawMesh(*vit)) { opaqueRenderList.erase(vit); } } } DrawWater(); std::list<int>::iterator lit; if (renderList.size() > 0) { for (lit = renderList.begin(); lit != renderList.end(); lit++) { if (!DrawMesh(*lit)) { renderList.erase(lit); } } } }
void Renderer::RenderScene() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); DrawSkybox(); DrawHeightMap(); DrawWater(); SwapBuffers(); }
//--------------------------------------------------------------------------- void __fastcall TRxViewDlg::StatusBarDrawPanel(TStatusBar *StatusBar, TStatusPanel *Panel, const TRect &Rect) { if( !m_pRxSet ) return; if( Panel == StatusBar->Panels->Items[sbMODE] ){ m_rcBar[sbMODE] = Rect; DrawMode(); } else if( Panel == StatusBar->Panels->Items[sbSN] ){ m_rcBar[sbSN] = Rect; DrawSN(); } else if( Panel == StatusBar->Panels->Items[sbFREQ] ){ m_rcBar[sbFREQ] = Rect; DrawFREQ(); } else if( Panel == StatusBar->Panels->Items[sbLEVEL] ){ if( !m_pBitmapLevel || ((Rect.Right-Rect.Left) != m_pBitmapLevel->Width) ){ m_rcBar[sbLEVEL] = Rect; m_levelXW = Rect.Right - Rect.Left; m_levelYW = Rect.Bottom - Rect.Top; if( !m_pBitmapLevel ){ m_pBitmapLevel = new Graphics::TBitmap; } m_pBitmapLevel->Width = m_levelXW; m_pBitmapLevel->Height = m_levelYW; } StatusBar->Canvas->Draw(m_rcBar[sbLEVEL].Left, m_rcBar[sbLEVEL].Top, m_pBitmapLevel); } else if( Panel == StatusBar->Panels->Items[sbWATER] ){ if( !m_pBitmapFFT || ((Rect.Right-Rect.Left) != m_pBitmapFFT->Width) ){ m_rcBar[sbWATER] = Rect; m_fftXW = Rect.Right - Rect.Left; m_fftYW = Rect.Bottom - Rect.Top; if( !m_pBitmapFFT ){ m_pBitmapFFT = new Graphics::TBitmap; } m_pBitmapFFT->Width = m_fftXW; m_pBitmapFFT->Height = m_fftYW; DrawWater(TRUE); } StatusBar->Canvas->Draw(m_rcBar[sbWATER].Left, m_rcBar[sbWATER].Top, m_pBitmapFFT); DrawWaterCursor(); } else if( Panel == StatusBar->Panels->Items[sbEND] ){ AnsiString as = PC->Font->Name; // TFontStyles fs = PC->Font->Style; // AddStyle(as, PC->Font->Charset, FontStyle2Code(fs)); AddStyle(as, PC->Font->Charset, 0); StatusBar->Canvas->TextRect(Rect, Rect.Left + 1, Rect.Top + 1, as.c_str()); } }
void Terrain::DrawTerrain(Vector CurrentCamera, const Vector viewFrustrum[]) { CameraEye = CurrentCamera; ViewFrustrum[0] = viewFrustrum[0]; ViewFrustrum[1] = viewFrustrum[1]; ViewFrustrum[2] = viewFrustrum[2]; ViewFrustrum[3] = viewFrustrum[3]; ROAM(TriangleTree.root); DrawSkyBox(); DrawTriangleTree(TriangleTree.root); glEnable(GL_BLEND); DrawWater(); glDisable(GL_BLEND); glFlush(); }
//--------------------------------------------------------------------------- void __fastcall TRxViewDlg::UpdateStatus(void) { if( !m_pRxSet ) return; DrawMode(); DrawSN(); DrawFREQ(); if( m_pBitmapLevel ){ DrawLevel(); StatusBar->Canvas->Draw(m_rcBar[sbLEVEL].Left, m_rcBar[sbLEVEL].Top, m_pBitmapLevel); } if( m_pBitmapFFT ){ DrawWater(FALSE); StatusBar->Canvas->Draw(m_rcBar[sbWATER].Left, m_rcBar[sbWATER].Top, m_pBitmapFFT); DrawWaterCursor(); } }
void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The matrix // Get the current position of the camera CVector3 vPos = g_Camera.Position(); CVector3 vNewPos = vPos; // Check if the camera is below the height of the terrain at x and z, // but we add 10 to make it so the camera isn't on the floor. if(vPos.y < Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10) { // Set the new position of the camera so it's above the terrain + 10 vNewPos.y = (float)Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10; // Get the difference of the y that the camera was pushed back up float temp = vNewPos.y - vPos.y; // Get the current view and increase it by the different the position was moved CVector3 vView = g_Camera.View(); vView.y += temp; // Set the new camera position. g_Camera.PositionCamera(vNewPos.x, vNewPos.y, vNewPos.z, vView.x, vView.y, vView.z, 0, 1, 0); } // Give OpenGL our camera position g_Camera.Look(); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Here comes the most technical part of our tutorial--clipping planes. // We turn the terrain upside-down, so we don't want the bottom sticking // out of the water, so we need to create a clipping plane that will // clip anything that is above it. In this case, (0, -1, 0) is the normal // of the plane to clip, and we finally give it out distance from the // origin--g_WaterHeight. double reflectPlane[] = {0.0f, -1.0f, 0.0f, g_WaterHeight}; glEnable(GL_CLIP_PLANE0); // Turn on clipping for plane 0 // This is where we select the clipping plane we want to use, and then the // plane's data is passed in as an array of floats (ABC and D). You can have // many clipping planes going, which is why we need to specify which one we want. glClipPlane(GL_CLIP_PLANE0, reflectPlane); // Now comes the reflection! // Pop on a new matrix so our translation/scaling doesn't effect other data glPushMatrix(); // We first need to translate the terrain to the water height multiplied by 2, // since we are reflecting it upside down at that height. glTranslatef(0.0f, g_WaterHeight*2.0f, 0.0f); // We then use glScale() to flip the terrain upside-down (-1 flips it). glScalef(1.0, -1.0, 1.0); // Since the terrain is upside-down we need to do front-face culling. glCullFace(GL_FRONT); // Now we render the terrain and the skybx upside-down for the reflection. RenderHeightMap(g_HeightMap); CreateSkyBox(500, 0, 500, 2000, 2000, 2000); // Now we can restore the app to back-face culling glCullFace(GL_BACK); // Leave the previous matrix and go back to the original matrix glPopMatrix(); // Since the reflection is already drawn, let's turn off clipping. glDisable(GL_CLIP_PLANE0); // Now we actually draw the water blended over the reflection, which // creates the effect that the reflection is in the water. We blend // with a simple alpha to one minus alpha blending function. The color // is set to a blue, with the alpha value at 50% (0.5). We don't want // the alpha too high or else we wouldn't see the reflection. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.5f, 0.5f, 0.9f, 0.5f); DrawWater(g_WaterHeight); glDisable(GL_BLEND); // Render the height map normally, right-side-up. RenderHeightMap(g_HeightMap); // Create the sky box and center it around the terrain CreateSkyBox(500, 0, 500, 2000, 2000, 2000); // This block of code right here is for an added effect of // what is draw when you are under the water. This isn't necessary, // but I thought I would add it to improve the tutorial's realism. // When we go underwater we want to be able to look up out of the // water. To do that we just render the water again, but change // the culling to front-face, then change our water color. Nothing special. // We could just do a check to see if we are under or over the water, // then only render the water once, but I think you can do that yourself. glCullFace(GL_FRONT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0f, 0.0f, 0.9f, 0.5f); DrawWater(g_WaterHeight); glDisable(GL_BLEND); glCullFace(GL_BACK); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Swap the backbuffers to the foreground SwapBuffers(g_hDC); }