// // Draw The Scene // void DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glClearColor(0.0f, 0.0f, 0.3f, 0.0f); // Black Background // begin scene --- BEGIN_BOT; RenderWalls(); RenderPlane(); SetLights(); driver_objects[STARS_OBJECT]->render(); Draw_Wall_List(); DrawExplosions(); DrawFireAnts(); END_BOT; // Draw the multiple sets of Heads up displays Super_DrawText(); Draw_Title(); DrawHUD(); } // end of the function
void BSP(const Mat4f& camera, std::size_t p) { assert(p < std::size_t(plane.size())); // the normal vector of the plane Vec4f normal(make_plane[p].Normal(), 0.0); // check if we are seeing the front or the back face GLfloat sign = ((camera*normal).z() >= 0.0f)? 1.0f: -1.0f; bool at_leaf = p+1 == plane.size(); gl.Enable(Functionality::ClipDistance, p); torus_clip_signs[p].Set(-sign); plane_clip_signs[p].Set(-sign); if(at_leaf) RenderTorus(); else BSP(camera, p+1); gl.Disable(Functionality::ClipDistance, p); RenderPlane(p); gl.Enable(Functionality::ClipDistance, p); torus_clip_signs[p].Set(+sign); plane_clip_signs[p].Set(+sign); if(at_leaf) RenderTorus(); else BSP(camera, p+1); gl.Disable(Functionality::ClipDistance, p); }
void DrawPlane(NxShape* plane) { NxPlaneShape* planeShape = plane->isPlane(); NxPlane p = planeShape->getPlane(); NxVec3 n=p.normal; n.normalize(); NxVec3 t1; NxVec3 t2; static const NxReal cos45 = 0.7071067811865475244008443621048490; if (fabs(n.z) > cos45) { NxReal a = n.y*n.y + n.z*n.z; NxReal k = NxReal(1.0)/NxMath::sqrt(a); t1.set(0,-n.z*k,n.y*k); t2.set(a*k,-n.x*t1.z,n.x*t1.y); } else { NxReal a = n.x*n.x + n.y*n.y; NxReal k = NxReal(1.0)/NxMath::sqrt(a); t1.set(-n.y*k,n.x*k,0); t2.set(-n.z*t1.y,n.z*t1.x,a*k); } NxMat34 pose; pose.M.setColumn(0, t2); pose.M.setColumn(1, n); pose.M.setColumn(2, t1); // We can't use this cause someone decided it was a good idea to support two plane representations // pose.t=p.pointInPlane(); pose.t = n * p.d; glPushMatrix(); glDisable(GL_LIGHTING); glColor4f(0.1f, 0.2f, 0.3f, 1.0f); SetupGLMatrix(pose.t, pose.M); glTranslatef(0,-0.1f,0); glScalef(1024,1,1024); RenderPlane(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_LIGHTING); glPopMatrix(); }
// // Draw The Scene // void DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glClearColor(0.0f, 0.0f, 0.3f, 0.0f); // Black Background //BEGIN_CAMERA // setup viewing camera BEGIN_BOT; //RenderGrid(); RenderWalls(); RenderPlane(); #if ENABLE_LIGHTS SetLights(); #endif driver_objects[STARS_OBJECT]->render(); Draw_Wall_List(); DrawExplosions(); // draw fire explosions DrawFireAnts(); // the mother of all enemies //END_CAMERA // end viewing camera END_BOT; // Draw the heads up display -- Super_DrawText(); Draw_Title(); DrawHUD(); } // end of the function
//-------------------------------------------------------------------------------------------------------------------- void RDX11RenderHelper::RenderWorldGrid(XMMATRIX& mtWorld, int size, int lineCount) { RenderPlane(mtWorld, CVector2(100,100)); SetWorldTM(mtWorld); float halfWidth = size/2.f; float lineWidth = size/50.f; CVertexPC v1,v2; for(int i = 0 ; i < lineCount ; i += 2) { v1.vPos.x = halfWidth - i/2 * lineWidth; v2.vPos.x = v1.vPos.x; v1.vPos.z = 0; v2.vPos.z = 0; if( i== 50 ) { v1.vPos.y = 0; v2.vPos.y = -halfWidth; } else { v1.vPos.y = halfWidth; v2.vPos.y = -halfWidth; } v1.color = COLOR_GRAY; v2.color = COLOR_GRAY; m_LineVertices.Add(v1); m_LineVertices.Add(v2); } for(int i = lineCount ; i < lineCount *2 ; i += 2) { v1.vPos.y = halfWidth - ( i - lineCount )/2 * lineWidth; v2.vPos.y = v1.vPos.y; v1.vPos.z = 0; v2.vPos.z = 0; if( i== 150 ) { v1.vPos.x = 0; v2.vPos.x = -halfWidth; } else { v1.vPos.x = halfWidth; v2.vPos.x = -halfWidth; } v1.color = COLOR_GRAY; v2.color = COLOR_GRAY; m_LineVertices.Add(v1); m_LineVertices.Add(v2); } v1.vPos = CVector3(0.0f, 0.0f, 0.0f); v1.color = COLOR_RED; m_LineVertices.Add(v1); v1.vPos = CVector3(halfWidth, 0.0f, 0.0f); v1.color = COLOR_RED; m_LineVertices.Add(v1); v1.vPos = CVector3(0.0f, 0.0f, 0.0f); v1.color = COLOR_BLUE; m_LineVertices.Add(v1); v1.vPos = CVector3(0.0f, 0.0f, halfWidth); v1.color = COLOR_BLUE; m_LineVertices.Add(v1); v1.vPos = CVector3(0.0f, 0, 0.0f); v1.color = COLOR_GREEN; m_LineVertices.Add(v1); v1.vPos = CVector3(0.0f, halfWidth, 0.0f); v1.color = COLOR_GREEN; m_LineVertices.Add(v1); GLOBAL::ShaderMgr()->Begin(SHADER_COLOR_VS, SHADER_COLOR_PS); DrawLine(); }
void Shadows::RenderScene() { unsigned int i; glDepthFunc(GL_LESS); switch (eDisplayMode) { default: //case E_NO_SHADOWS: // RenderGeometry(uiProgram[E_DIFFUSE]); // break; //case E_SHADOW_VOLUMES: // RenderGeometry(uiProgram[E_DIFFUSE]); // for (i = 0; i < iNumLights; i++) // { // glEnable(GL_LIGHT0 + i); // glLightfv(GL_LIGHT0 + i, GL_POSITION, light[i].fPos); // } // ShowShadowVolume(); // break; case E_SHADOW_VOLUMES: case E_SHADOWS: for (i = 0; i < iNumLights; i++) { glEnable(GL_LIGHT0 + i); glLightfv(GL_LIGHT0 + i, GL_POSITION, light[i].fPos); } /* First, render all geometry with color and depth write enabled */ RenderGeometry(uiProgram[E_DIFFUSE]); /* Then, render the shadow volumes with color and depth write disabled. Use the Z-fail approach */ for (i = 0; i < iNumLights; i++) { RenderShadowVolumes(i); /* Finally, render again all the geometry setting a uniform transparency factor affecting only non-zero stencil pixels (areas in shadow) */ glDepthFunc(GL_EQUAL); // Enable Stencil Test glEnable(GL_STENCIL_TEST); // update the color only where the stencil value is 0 glStencilFunc(GL_NOTEQUAL, 0, ~0); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //RenderGeometry(uiProgram[E_DIFFUSE]); RenderGeometry(uiProgram[E_SHADOW]); glDisable(GL_STENCIL_TEST); glDisable(GL_BLEND); glDepthFunc(GL_LESS); } break; /* E_STENCIL is a debug mode used to render visually the values in the stencil buffer. Start with same approach as normal stencil rendering, then render multiple passes corresponding to different values in the stencil buffer. */ case E_STENCIL: for (i = 0; i < iNumLights; i++) { glEnable(GL_LIGHT0 + i); glLightfv(GL_LIGHT0 + i, GL_POSITION, light[i].fPos); } RenderGeometry(uiProgram[E_DIFFUSE]); for (i = 0; i < iNumLights; i++) { RenderShadowVolumes(i); // re-draw the model with the light enabled only where // it has previously been drawn glDisable(GL_DEPTH_TEST); // update the color only where the stencil value is 0 glEnable(GL_STENCIL_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glEnable(GL_BLEND); glDisable(GL_CULL_FACE); glUseProgram(uiProgram[E_PLANE]); for (unsigned int j = 1; j < 5; j++) { glStencilFunc(GL_EQUAL, j, ~0); RenderPlane(uiProgram[E_PLANE], Colors + (j-1) * 4); } glStencilFunc(GL_GEQUAL, 5, ~0); RenderPlane(uiProgram[E_PLANE], Colors + 16 * 4); glDisable(GL_STENCIL_TEST); glEnable(GL_CULL_FACE); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } break; } }