//Called to update the display. //You should call glutSwapBuffers after all of your rendering to display what you rendered. //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function. public override void display() { GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.ClearDepth(1.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); if ((g_pConeMesh != null) && (g_pCylinderMesh != null) && (g_pCubeTintMesh != null) && (g_pCubeColorMesh != null) && (g_pPlaneMesh != null)) { MatrixStack modelMatrix = new MatrixStack(); //Render the ground plane. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Scale(100.0f, 1.0f, 100.0f); GL.UseProgram(UniformColor.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColor.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColor.baseColorUnif, 0.302f, 0.416f, 0.0589f, 1.0f); g_pPlaneMesh.Render(); GL.UseProgram(0); } //Draw the trees DrawForest(modelMatrix); //Draw the building. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(20.0f, 0.0f, -10.0f); DrawParthenon(modelMatrix); } if (g_bDrawLookatPoint) using (PushStack pushstack = new PushStack(modelMatrix)) { GL.Disable(EnableCap.DepthTest); modelMatrix.Translate(Camera.g_camTarget); modelMatrix.Scale(1.0f, 1.0f, 1.0f); GL.UseProgram(ObjectColor.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(ObjectColor.modelToWorldMatrixUnif, false, ref mm); g_pCubeColorMesh.Render(); GL.UseProgram(0); GL.Enable(EnableCap.DepthTest); } } }
public override void display() { ClearDisplay(); if (current_mesh != null) { MatrixStack modelMatrix = new MatrixStack(); using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(Camera.g_camTarget); modelMatrix.Translate(0f, 0f, 0f); modelMatrix.Scale(15.0f, 15.0f, 15.0f); modelMatrix.Rotate(axis, angle); angle = angle + 1f; GL.UseProgram(currentProgram.theProgram); Matrix4 mm = modelMatrix.Top(); if (noWorldMatrix) { Matrix4 cm2 = Matrix4.Mult(mm, cm); GL.UniformMatrix4(currentProgram.modelToCameraMatrixUnif, false, ref cm2); if (currentProgram.normalModelToCameraMatrixUnif != 0) { Matrix3 normalModelToCameraMatrix = Matrix3.Identity; Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity, Matrix4.CreateTranslation(dirToLight)); normalModelToCameraMatrix = new Matrix3(applyMatrix); normalModelToCameraMatrix.Invert(); GL.UniformMatrix3(currentProgram.normalModelToCameraMatrixUnif, false, ref normalModelToCameraMatrix); //Matrix4 cameraToClipMatrix = Matrix4.Identity; //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix); } //Matrix4 cameraToClipMatrix = Matrix4.Identity; //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix); } else { GL.UniformMatrix4(currentProgram.modelToWorldMatrixUnif, false, ref mm); } } current_mesh.Render(); GL.UseProgram(0); } }
public override void display() { ClearDisplay(); GL.FrontFace(FrontFaceDirection.Cw); quaternionText.Draw(); axisAngleText.Draw(); GL.FrontFace(FrontFaceDirection.Ccw); if (meshes[currentMesh] != null) { MatrixStack modelMatrix = new MatrixStack(); modelMatrix.Scale(0.8f); modelMatrix.Translate(0.0f, 0.0f, 0f); // Apply object transforms first modelMatrix.ApplyMatrix(g_objtPole.CalcMatrix()); // End Object Pole Code using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Scale(cubeScaleFactor); GL.UseProgram(programs[currentProgram].theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(programs[currentProgram].modelToWorldMatrixUnif, false, ref mm); if (programs[currentProgram].baseColorUnif != -1) { GL.Uniform4(programs[currentProgram].baseColorUnif, 0.5f, 0.5f, 0f, 1.0f); } meshes[cube].Render(); } using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(new Vector3(0f, 0.4f, 0.0f)); modelMatrix.Scale(cylinderScaleFactor); GL.UseProgram(programs[currentProgram].theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(programs[currentProgram].modelToWorldMatrixUnif, false, ref mm); if (programs[currentProgram].baseColorUnif != -1) { GL.Uniform4(programs[currentProgram].baseColorUnif, 0.0f, 0.5f, 0.5f, 1.0f); } meshes[cylinder].Render(); } GL.UseProgram(0); if (perspectiveAngle != newPerspectiveAngle) { perspectiveAngle = newPerspectiveAngle; reshape(); } } if (updateText) { quaternionText.UpdateText(QuaternionString()); axisAngleText.UpdateText(AxisAngeString()); updateText = false; } }
public override void display() { ClearDisplay(); if((g_pPlaneMesh != null) && (g_pCylinderMesh != null)) { MatrixStack modelMatrix = new MatrixStack(); modelMatrix.SetMatrix(g_viewPole.CalcMatrix()); Vector4 lightDirCameraSpace = Vector4.Transform(g_lightDirection, modelMatrix.Top()); ProgramData whiteDiffuse = g_bShowAmbient ? g_WhiteAmbDiffuseColor : g_WhiteDiffuseColor; ProgramData vertexDiffuse = g_bShowAmbient ? g_VertexAmbDiffuseColor : g_VertexDiffuseColor; if(g_bShowAmbient) { GL.UseProgram(whiteDiffuse.theProgram); GL.Uniform4(whiteDiffuse.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f); GL.Uniform4(whiteDiffuse.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f); GL.UseProgram(0); GL.UseProgram(vertexDiffuse.theProgram); GL.Uniform4(vertexDiffuse.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f); GL.Uniform4(vertexDiffuse.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f); GL.UseProgram(0); } else { GL.UseProgram(whiteDiffuse.theProgram); GL.Uniform4(whiteDiffuse.lightIntensityUnif, 0.5f, 0.5f, 0.5f, 0.5f); GL.UseProgram(0); GL.UseProgram(vertexDiffuse.theProgram); GL.Uniform4(vertexDiffuse.lightIntensityUnif, 0.5f, 0.5f, 0.5f, 0.5f); GL.UseProgram(0); } GL.UseProgram(whiteDiffuse.theProgram); Vector3 dirToLight = new Vector3(lightDirCameraSpace.X, lightDirCameraSpace.Y, lightDirCameraSpace.Z); GL.Uniform3(whiteDiffuse.dirToLightUnif, dirToLight); GL.UseProgram(0); GL.UseProgram(vertexDiffuse.theProgram); GL.Uniform3(vertexDiffuse.dirToLightUnif, dirToLight); GL.UseProgram(0); //Render the ground plane. using ( PushStack pushstack = new PushStack(modelMatrix)) { GL.UseProgram(whiteDiffuse.theProgram); //modelMatrix.Scale(new Vector3(10f, 10f, 1f)); //modelMatrix.ApplyMatrix(g_objtPole.CalcMatrix()); //modelMatrix.Translate(new Vector3(0f, 0f, -10f)); Matrix4 mm = modelMatrix.Top(); planeModelmatrix = mm; //mm = Matrix4.Identity; // TEST GL.UniformMatrix4(whiteDiffuse.modelToCameraMatrixUnif, false, ref mm); //projData.cameraToClipMatrix = Matrix4.Identity; // Test GL.UniformMatrix4(whiteDiffuse.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); Matrix3 normMatrix = new Matrix3(modelMatrix.Top()); //normMatrix.Normalize(); //normMatrix = Matrix3.Identity; // TEST GL.UniformMatrix3(whiteDiffuse.normalModelToCameraMatrixUnif, false, ref normMatrix); g_pPlaneMesh.Render(); GL.UseProgram(0); } //Render the Cylinder using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.ApplyMatrix(g_objtPole.CalcMatrix()); //modelMatrix.Scale(0.05f); modelMatrix.Translate(new Vector3(0f, 0.0f, -10f)); coloredCylinderModelmatrix = modelMatrix.Top (); if(g_bDrawColoredCyl) { GL.UseProgram(vertexDiffuse.theProgram); Matrix4 mm = modelMatrix.Top(); //mm = Matrix4.Identity; // TEST GL.UniformMatrix4(vertexDiffuse.modelToCameraMatrixUnif, false, ref mm); //projData.cameraToClipMatrix = Matrix4.Identity; // TEST GL.UniformMatrix4(vertexDiffuse.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); Matrix3 normMatrix = new Matrix3(modelMatrix.Top()); //normMatrix = Matrix3.Identity; // TEST GL.UniformMatrix3(vertexDiffuse.normalModelToCameraMatrixUnif, false, ref normMatrix); g_pCylinderMesh.Render("lit-color"); } else { GL.UseProgram(whiteDiffuse.theProgram); Matrix4 mm = modelMatrix.Top(); //mm = Matrix4.Identity; // TEST GL.UniformMatrix4(whiteDiffuse.modelToCameraMatrixUnif, false, ref mm); //projData.cameraToClipMatrix = Matrix4.Identity; // TEST GL.UniformMatrix4(whiteDiffuse.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); Matrix3 normMatrix = new Matrix3(modelMatrix.Top()); //normMatrix = Matrix3.Identity; // TEST GL.UniformMatrix3(whiteDiffuse.normalModelToCameraMatrixUnif, false, ref normMatrix); g_pCylinderMesh.Render("lit"); } GL.UseProgram(0); } } }
public override void display() { ClearDisplay(); if (meshes[currentMesh] != null) { MatrixStack modelMatrix = new MatrixStack(); using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Rotate(axis, angle); // rotate last to leave in place modelMatrix.Translate(Camera.g_camTarget); modelMatrix.Scale(initialScale.X / scaleFactor.X, initialScale.Y / scaleFactor.Y, initialScale.Z / scaleFactor.Z); GL.UseProgram(currentProgram.theProgram); Matrix4 mm = modelMatrix.Top(); if (noWorldMatrix) { Matrix4 cm2 = Matrix4.Mult(mm, cm); GL.UniformMatrix4(currentProgram.modelToCameraMatrixUnif, false, ref cm2); if (currentProgram.normalModelToCameraMatrixUnif != 0) { Matrix3 normalModelToCameraMatrix = Matrix3.Identity; Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity, Matrix4.CreateTranslation(dirToLight)); normalModelToCameraMatrix = new Matrix3(applyMatrix); normalModelToCameraMatrix.Invert(); GL.UniformMatrix3(currentProgram.normalModelToCameraMatrixUnif, false, ref normalModelToCameraMatrix); //Matrix4 cameraToClipMatrix = Matrix4.Identity; //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix); } //Matrix4 cameraToClipMatrix = Matrix4.Identity; //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix); } else { GL.UniformMatrix4(currentProgram.modelToWorldMatrixUnif, false, ref mm); } } if (renderWithString) { try { meshes[currentMesh].Render(renderString); } catch (Exception ex) { renderWithString = false; MessageBox.Show("Error displaying mesh wih render string " + renderString + " " + ex.ToString()); } } else { meshes[currentMesh].Render(); } GL.UseProgram(0); if (perspectiveAngle != newPerspectiveAngle) { perspectiveAngle = newPerspectiveAngle; reshape(); } } }
public override void display() { if(g_pScene == null) return; g_timer.Update(); GL.ClearColor(0.8f, 0.8f, 0.8f, 1.0f); GL.ClearDepth(1.0f); GL.Clear(ClearBufferMask.ColorBufferBit |ClearBufferMask.DepthBufferBit); MatrixStack modelMatrix = new MatrixStack(); modelMatrix.ApplyMatrix(g_viewPole.CalcMatrix()); BuildLights(modelMatrix.Top()); if (rightMultiply) { g_nodes[0].NodeSetOrient(Quaternion.FromAxisAngle(new Vector3(0.0f, 1.0f, 0.0f), 360.0f * g_timer.GetAlpha()/reduceSpeed)); g_nodes[3].NodeSetOrient(Quaternion.Multiply(g_spinBarOrient, Quaternion.FromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), 360.0f * g_timer.GetAlpha()/reduceSpeed))); } else { g_nodes[0].NodeSetOrient(Quaternion.FromAxisAngle(new Vector3(0.0f, 1.0f, 0.0f), 360.0f * g_timer.GetAlpha()/reduceSpeed)); g_nodes[3].NodeSetOrient(Quaternion.Multiply( Quaternion.FromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), 360.0f * g_timer.GetAlpha()/reduceSpeed), g_spinBarOrient)); } { MatrixStack persMatrix = new MatrixStack(); persMatrix.Perspective(60.0f, (width/2f / height), g_fzNear, g_fzFar); // added //persMatrix.Translate(translateVector); //persMatrix.Scale(scaleFactor); // end added ProjectionBlock projData = new ProjectionBlock(); projData.cameraToClipMatrix = persMatrix.Top(); GL.UseProgram(g_unlitProg); GL.UniformMatrix4(g_unlitCameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); GL.UseProgram(g_pScene.FindProgram("p_lit")); GL.UniformMatrix4(g_litCameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); } GL.Viewport(0, 0, width/2, height); g_pScene.Render(modelMatrix.Top()); if(g_bDrawCameraPos) { using (PushStack pushstack = new PushStack(modelMatrix))//Draw lookat point. { modelMatrix.SetIdentity(); modelMatrix.Translate(new Vector3(0.0f, 0.0f, -g_viewPole.GetView().radius)); modelMatrix.Scale(0.5f); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); GL.UseProgram(g_unlitProg); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_unlitModelToCameraMatrixUnif, false, ref mm); GL.Uniform4(g_unlitObjectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f); g_pSphereMesh.Render("flat"); GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); GL.Uniform4(g_unlitObjectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f); g_pSphereMesh.Render("flat"); } } { MatrixStack persMatrix = new MatrixStack(); Matrix4 applyMatrix = g_persViewPole.CalcMatrix(); applyMatrix.Row3 = Vector4.Zero; applyMatrix.Column3 = Vector4.Zero; applyMatrix.M44 = 1f; persMatrix.ApplyMatrix(applyMatrix); persMatrix.Perspective(60.0f, (width/2f / height), g_fzNear, g_fzFar); // added persMatrix.Translate(translateVector); persMatrix.Scale(scaleFactor); // end added ProjectionBlock projData = new ProjectionBlock(); projData.cameraToClipMatrix = persMatrix.Top(); GL.UseProgram(g_unlitProg); GL.UniformMatrix4(g_unlitCameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); GL.UseProgram(g_pScene.FindProgram("p_lit")); GL.UniformMatrix4(g_litCameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); } if(!g_bDepthClampProj) GL.Disable(EnableCap.DepthClamp); GL.Viewport(width/2, 0, width/2, height); g_pScene.Render(modelMatrix.Top()); GL.Enable(EnableCap.DepthClamp); }
public override void display() { g_lightTimer.Update(); GL.ClearColor(0.75f, 0.75f, 1.0f, 1.0f); GL.ClearDepth(1.0f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); if((g_pObjectMesh != null) && (g_pCubeMesh != null)) { MatrixStack modelMatrix = new MatrixStack(); modelMatrix.SetMatrix(g_viewPole.CalcMatrix()); Matrix4 worldToCamMat = modelMatrix.Top(); LightBlock lightData = new LightBlock(NUMBER_OF_LIGHTS); lightData.ambientIntensity = new Vector4(0.2f, 0.2f, 0.2f, 1.0f); lightData.lightAttenuation = g_fLightAttenuation; Vector3 globalLightDirection = new Vector3(0.707f, 0.707f, 0.0f); lightData.lights[0].cameraSpaceLightPos = Vector4.Transform(new Vector4(globalLightDirection, 0.0f), worldToCamMat); lightData.lights[0].lightIntensity = new Vector4(0.6f, 0.6f, 0.6f, 1.0f); lightData.lights[1].cameraSpaceLightPos = Vector4.Transform(CalcLightPosition(), worldToCamMat); lightData.lights[1].lightIntensity = new Vector4(0.4f, 0.4f, 0.4f, 1.0f); g_litShaderProg.lightBlock.Update(lightData); g_litTextureProg.lightBlock.Update(lightData); using ( PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.ApplyMatrix(g_objtPole.CalcMatrix()); modelMatrix.Scale(2.0f); Matrix3 normMatrix = new Matrix3(modelMatrix.Top()); normMatrix.Transpose(); //TEST normMatrix = Matrix3.Identity; //normMatrix = glm::transpose(glm::inverse(normMatrix)); ProgramData prog = g_bUseTexture ? g_litTextureProg : g_litShaderProg; GL.UseProgram(prog.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(prog.modelToCameraMatrixUnif, false, ref mm); GL.UniformMatrix3(prog.normalModelToCameraMatrixUnif, false, ref normMatrix); GL.ActiveTexture(TextureUnit.Texture0 + g_gaussTexUnit); GL.BindTexture(TextureTarget.Texture1D, g_gaussTextures[g_currTexture]); GL.BindSampler(g_gaussTexUnit, g_gaussSampler); g_pObjectMesh.Render("lit"); GL.BindSampler(g_gaussTexUnit, 0); GL.BindTexture(TextureTarget.Texture1D, 0); GL.UseProgram(0); } if(g_bDrawLights) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(new Vector3(CalcLightPosition())); modelMatrix.Scale(0.25f); GL.UseProgram(g_Unlit.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm); Vector4 lightColor = new Vector4(1f, 1f, 1f, 1f); GL.Uniform4(g_Unlit.objectColorUnif, ref lightColor); g_pCubeMesh.Render("flat"); } modelMatrix.Translate(globalLightDirection * 100.0f); modelMatrix.Scale(5.0f); Matrix4 mm2 = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm2); g_pCubeMesh.Render("flat"); GL.UseProgram(0); } if(g_bDrawCameraPos) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.SetIdentity(); modelMatrix.Translate(new Vector3(0.0f, 0.0f, -g_viewPole.GetView().radius)); modelMatrix.Scale(0.25f); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); GL.UseProgram(g_Unlit.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm); GL.Uniform4(g_Unlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f); g_pCubeMesh.Render("flat"); GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); GL.Uniform4(g_Unlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f); g_pCubeMesh.Render("flat"); } } } }
public override void display() { g_LightTimer.Update(); ClearDisplay(); if((g_pPlaneMesh != null) && (g_pCylinderMesh != null) && ( g_pCubeMesh != null)) { MatrixStack modelMatrix = new MatrixStack(); modelMatrix.SetMatrix(g_viewPole.CalcMatrix()); Vector4 worldLightPos = CalcLightPosition(); Vector4 lightPosCameraSpace = Vector4.Transform(worldLightPos, modelMatrix.Top()); ProgramData pWhiteProgram; ProgramData pVertColorProgram; if(g_bUseFragmentLighting) { pWhiteProgram = g_FragWhiteDiffuseColor; pVertColorProgram = g_FragVertexDiffuseColor; } else { pWhiteProgram = g_WhiteDiffuseColor; pVertColorProgram = g_VertexDiffuseColor; } GL.UseProgram(pWhiteProgram.theProgram); GL.Uniform4(pWhiteProgram.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f); GL.Uniform4(pWhiteProgram.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f); GL.UniformMatrix4(pWhiteProgram.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(pVertColorProgram.theProgram); GL.Uniform4(pVertColorProgram.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f); GL.Uniform4(pVertColorProgram.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f); GL.UniformMatrix4(pVertColorProgram.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); //Render the ground plane. using (PushStack pushstack = new PushStack(modelMatrix)) { GL.UseProgram(pWhiteProgram.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(pWhiteProgram.modelToCameraMatrixUnif, false, ref mm); Matrix4 invTransform = modelMatrix.Top().Inverted(); Vector4 lightPosModelSpace = Vector4.Transform(lightPosCameraSpace, invTransform); Vector3 lightPos = new Vector3(lightPosModelSpace.X, lightPosModelSpace.Y, lightPosModelSpace.Z); GL.Uniform3(pWhiteProgram.modelSpaceLightPosUnif, ref lightPos); g_pPlaneMesh.Render(); GL.UseProgram(0); } //Render the Cylinder using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.ApplyMatrix(g_objtPole.CalcMatrix()); //modelMatrix.Translate(new Vector3(0f, 0f, 10f)); coloredCylinderModelmatrix = modelMatrix.Top(); if(g_bScaleCyl) modelMatrix.Scale(1.0f, 1.0f, 0.2f); Matrix4 mm = modelMatrix.Top(); Matrix4 invTransform = modelMatrix.Top().Inverted(); Vector4 lightPosModelSpace = Vector4.Transform(lightPosCameraSpace, invTransform); if(g_bDrawColoredCyl) { GL.UseProgram(pVertColorProgram.theProgram); GL.UniformMatrix4(pVertColorProgram.modelToCameraMatrixUnif, false, ref mm); Vector3 lightPos = new Vector3(lightPosModelSpace.X, lightPosModelSpace.Y, lightPosModelSpace.Z); GL.Uniform3(pVertColorProgram.modelSpaceLightPosUnif, ref lightPos); GL.UniformMatrix4(pVertColorProgram.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); g_pCylinderMesh.Render("lit-color"); } else { GL.UseProgram(pWhiteProgram.theProgram); GL.UniformMatrix4(pWhiteProgram.modelToCameraMatrixUnif, false, ref mm); Vector3 lightPos = new Vector3(lightPosModelSpace.X, lightPosModelSpace.Y, lightPosModelSpace.Z); GL.Uniform3(pWhiteProgram.modelSpaceLightPosUnif, ref lightPos); GL.UniformMatrix4(pWhiteProgram.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); g_pCylinderMesh.Render("lit"); } GL.UseProgram(0); } //Render the light if(g_bDrawLight) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(new Vector3(worldLightPos)); modelMatrix.Scale(0.1f, 0.1f, 0.1f); GL.UseProgram(g_Unlit.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm); GL.Uniform4(g_Unlit.baseColorUnif, 0.8078f, 0.8706f, 0.9922f, 1.0f); GL.UniformMatrix4(g_Unlit.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); g_pCubeMesh.Render("flat"); } } } }
public override void display() { if(g_pScene == null) return; g_lights.UpdateTime(); float gamma = g_isGammaCorrect ? g_gammaValue : 1.0f; Vector4 bkg = g_lights.GetBackgroundColor(); GL.ClearColor(bkg[0], bkg[1], bkg[2], bkg[3]); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); MatrixStack modelMatrix = new MatrixStack(); modelMatrix.SetMatrix(g_viewPole.CalcMatrix()); Matrix4 worldToCamMat = modelMatrix.Top(); LightBlock lightData = g_lights.GetLightInformationGamma(worldToCamMat); lightData.gamma = gamma; foreach (SceneProgramData spd in g_Programs) { spd.lightBlock.Update(lightData); } if(g_pScene != null) { using ( PushStack pushstack = new PushStack(modelMatrix)) { g_pScene.Draw(modelMatrix, g_materialBlockIndex, g_lights.GetTimerValue("tetra")); } } //Render the sun if (renderSun) { using ( PushStack pushstack = new PushStack(modelMatrix)) { Vector3 sunlightDir = new Vector3(g_lights.GetSunlightDirection()); modelMatrix.Translate(sunlightDir * 500.0f); modelMatrix.Scale(30.0f, 30.0f, 30.0f); GL.UseProgram(g_Unlit.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm); Vector4 lightColor = GammaCorrect(g_lights.GetSunlightIntensity(), gamma); GL.Uniform4(g_Unlit.objectColorUnif, lightColor); g_pScene.GetSphereMesh().Render("flat"); } } //Render the lights if(g_bDrawLights) { for(int light = 0; light < g_lights.GetNumberOfPointLights(); light++) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(g_lights.GetWorldLightPosition(light)); GL.UseProgram(g_Unlit.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm); Vector4 lightColor = GammaCorrect(g_lights.GetPointLightIntensity(light), gamma); GL.Uniform4(g_Unlit.objectColorUnif, lightColor); g_pScene.GetCubeMesh().Render("flat"); } } } if(g_bDrawCameraPos) { using ( PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.SetIdentity(); modelMatrix.Translate(new Vector3(0.0f, 0.0f, -g_viewPole.GetView().radius)); GL.Disable(EnableCap.DepthTest); GL.DepthMask(false); GL.UseProgram(g_Unlit.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(g_Unlit.modelToCameraMatrixUnif, false, ref mm); GL.Uniform4(g_Unlit.objectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f); g_pScene.GetCubeMesh().Render("flat"); GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); GL.Uniform4(g_Unlit.objectColorUnif, 1.0f, 1.0f, 1.0f, 1.0f); g_pScene.GetCubeMesh().Render("flat"); } } }
public override void reshape() { MatrixStack persMatrix = new MatrixStack(); persMatrix.Perspective(45.0f, (width / (float)height), g_fzNear, g_fzFar); // added persMatrix.Translate(-0.5f, 0.0f, -3f); persMatrix.Scale(0.01f); // end added ProjectionBlock projData = new ProjectionBlock(); projData.cameraToClipMatrix = persMatrix.Top(); foreach(SceneProgramData spd in g_Programs) { GL.UseProgram(spd.theProgram); GL.UniformMatrix4(spd.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); } GL.UseProgram(g_Unlit.theProgram); GL.UniformMatrix4(g_Unlit.cameraToClipMatrixUnif, false, ref projData.cameraToClipMatrix); GL.UseProgram(0); GL.Viewport(0, 0, width, height); }
public override void display() { GL.Disable(EnableCap.DepthTest); ClearDisplay(); if (drawWalls) backWall.Draw(); if (drawWalls) leftWall.Draw(); if (drawWalls) rightWall.Draw(); if (drawWalls) topWall.Draw(); if (drawWalls) bottomWall.Draw(); ball.Draw(); if (current_mesh != null) { MatrixStack modelMatrix = new MatrixStack(); using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Rotate(axis, angle); // rotate last to leave in place modelMatrix.Translate(position); modelMatrix.Scale(15.0f, 15.0f, 15.0f); ballModelMatrix = modelMatrix.Top(); GL.UseProgram(currentProgram.theProgram); Matrix4 mm = modelMatrix.Top(); if (noWorldMatrix) { Matrix4 cm2 = Matrix4.Mult(mm, worldToCameraMatrix); GL.UniformMatrix4(currentProgram.modelToCameraMatrixUnif, false, ref cm2); if (currentProgram.normalModelToCameraMatrixUnif != 0) { Matrix3 normalModelToCameraMatrix = Matrix3.Identity; Matrix4 applyMatrix = Matrix4.Mult(Matrix4.Identity, Matrix4.CreateTranslation(dirToLight)); normalModelToCameraMatrix = new Matrix3(applyMatrix); normalModelToCameraMatrix.Invert(); GL.UniformMatrix3(currentProgram.normalModelToCameraMatrixUnif, false, ref normalModelToCameraMatrix); //Matrix4 cameraToClipMatrix = Matrix4.Identity; //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix); } //Matrix4 cameraToClipMatrix = Matrix4.Identity; //GL.UniformMatrix4(currentProgram.cameraToClipMatrixUnif, false, ref cameraToClipMatrix); } else { GL.UniformMatrix4(currentProgram.modelToWorldMatrixUnif, false, ref mm); } } if (renderWithString) { current_mesh.Render(renderString); } else { current_mesh.Render(); } GL.UseProgram(0); if (perspectiveAngle != newPerspectiveAngle) { perspectiveAngle = newPerspectiveAngle; reshape(); } } if (drawWalls) frontWall.Draw(); if (pause == false) { UpdatePosition(); if (rotateWorld) { RotateWorldSub(); } } }
void DrawParthenon(MatrixStack modelMatrix) { //Draw base. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Scale(g_fParthenonWidth, g_fParthenonBaseHeight, g_fParthenonLength); modelMatrix.Translate(0.0f, 0.5f, 0.0f); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f); g_pCubeTintMesh.Render(); GL.UseProgram(0); } //Draw top. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(0.0f, g_fParthenonColumnHeight + g_fParthenonBaseHeight, 0.0f); modelMatrix.Scale(g_fParthenonWidth, g_fParthenonTopHeight, g_fParthenonLength); modelMatrix.Translate(0.0f, 0.5f, 0.0f); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f); g_pCubeTintMesh.Render(); GL.UseProgram(0); } //Draw columns. float fFrontZVal = (g_fParthenonLength / 2.0f) - 1.0f; float fRightXVal = (g_fParthenonWidth / 2.0f) - 1.0f; for (int iColumnNum = 0; iColumnNum < (int)(g_fParthenonWidth / 2.0f); iColumnNum++) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate((2.0f * iColumnNum) - (g_fParthenonWidth / 2.0f) + 1.0f, g_fParthenonBaseHeight, fFrontZVal); DrawColumn(modelMatrix, g_fParthenonColumnHeight); } using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate((2.0f * iColumnNum) - (g_fParthenonWidth / 2.0f) + 1.0f, g_fParthenonBaseHeight, -fFrontZVal); DrawColumn(modelMatrix, g_fParthenonColumnHeight); } } //Don't draw the first or last columns, since they've been drawn already. for (int iColumnNum = 1; iColumnNum < (int)((g_fParthenonLength - 2.0f) / 2.0f); iColumnNum++) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(fRightXVal, g_fParthenonBaseHeight, (2.0f * iColumnNum) - (g_fParthenonLength / 2.0f) + 1.0f); DrawColumn(modelMatrix, g_fParthenonColumnHeight); } using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(-fRightXVal, g_fParthenonBaseHeight, (2.0f * iColumnNum) - (g_fParthenonLength / 2.0f) + 1.0f); DrawColumn(modelMatrix, g_fParthenonColumnHeight); } } //Draw interior. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(0.0f, 1.0f, 0.0f); modelMatrix.Scale(g_fParthenonWidth - 6.0f, g_fParthenonColumnHeight, g_fParthenonLength - 6.0f); modelMatrix.Translate(0.0f, 0.5f, 0.0f); GL.UseProgram(ObjectColor.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(ObjectColor.modelToWorldMatrixUnif, false, ref mm); g_pCubeColorMesh.Render(); GL.UseProgram(0); } //Draw headpiece. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate( 0.0f, g_fParthenonColumnHeight + g_fParthenonBaseHeight + (g_fParthenonTopHeight / 2.0f), g_fParthenonLength / 2.0f); modelMatrix.RotateX(-135.0f); modelMatrix.RotateY(45.0f); GL.UseProgram(ObjectColor.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(ObjectColor.modelToWorldMatrixUnif, false, ref mm); g_pCubeColorMesh.Render(); GL.UseProgram(0); } }
void DrawColumn(MatrixStack modelMatrix, float fHeight) { //Draw the bottom of the column. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Scale(1.0f, g_fColumnBaseHeight, 1.0f); modelMatrix.Translate(0.0f, 0.5f, 0.0f); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 1.0f, 1.0f, 1.0f, 1.0f); g_pCubeTintMesh.Render(); GL.UseProgram(0); } //Draw the top of the column. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(new Vector3(0.0f, fHeight - g_fColumnBaseHeight, 0.0f)); modelMatrix.Scale(new Vector3(1.0f, g_fColumnBaseHeight, 1.0f)); modelMatrix.Translate(new Vector3(0.0f, 0.5f, 0.0f)); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f); g_pCubeTintMesh.Render(); GL.UseProgram(0); } //Draw the main column. using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(new Vector3(0.0f, g_fColumnBaseHeight, 0.0f)); modelMatrix.Scale(new Vector3(0.8f, fHeight - (g_fColumnBaseHeight * 2.0f), 0.8f)); modelMatrix.Translate(new Vector3(0.0f, 0.5f, 0.0f)); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 0.9f, 0.9f, 0.9f, 0.9f); g_pCylinderMesh.Render(); GL.UseProgram(0); } }
static void DrawTree(MatrixStack modelMatrix, float fTrunkHeight, float fConeHeight) { using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Scale(1.0f, fTrunkHeight, 1.0f); modelMatrix.Translate(0.0f, 0.5f, 0.0f); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 0.694f, 0.4f, 0.106f, 1.0f); g_pCylinderMesh.Render(); GL.UseProgram(0); } //Draw the treetop using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(0.0f, fTrunkHeight, 0.0f); modelMatrix.Scale(3.0f, fConeHeight, 3.0f); GL.UseProgram(UniformColorTint.theProgram); Matrix4 mm = modelMatrix.Top(); GL.UniformMatrix4(UniformColorTint.modelToWorldMatrixUnif, false, ref mm); GL.Uniform4(UniformColorTint.baseColorUnif, 0.0f, 1.0f, 0.0f, 1.0f); g_pConeMesh.Render(); GL.UseProgram(0); } }
static void DrawForest(MatrixStack modelMatrix) { for (int iTree = 0; iTree < TreeData.g_forest.Length; iTree++) { TreeData currTree = TreeData.g_forest[iTree]; using (PushStack pushstack = new PushStack(modelMatrix)) { modelMatrix.Translate(currTree.fXPos, 0.0f, currTree.fZPos); DrawTree(modelMatrix, currTree.fTrunkHeight, currTree.fConeHeight); } } }