示例#1
0
        private void BasicVis_RenderFrame(object sender, FrameEventArgs e)
        {
            OpenGLUtil.UseFrameBuffer(frameBufferID);                                  // render to our custom framebuffer
            GL.Viewport(0, 0, 1024, 1024);                                             // render on teh entire framebuffer

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // clear the screen
            depthProgram.UseProgram();                                                 // use the depth program

            // camera properties
            Matrix4 proj  = Matrix4.CreateOrthographic(100, 100, 0, 100);
            Matrix4 view  = Matrix4.LookAt(new Vector3(4, 3, 3), Vector3.Zero, new Vector3(0, 1, 0));
            Matrix4 model = Matrix4.Identity;

            depthProgram.SetMVP(model * view * proj);

            depthProgram.EnableAttributes();
            depthProgram.LoadBuffer(vertexBufferID);

            GL.DrawArrays(PrimitiveType.Triangles, 0, vertexBufferData.Length); // here the fragment shader will automatically write the depth to the texture bc of location 0
            depthProgram.DisableAttributes();

            OpenGLUtil.UseFrameBuffer(0);                                              // now render to the screen
            GL.Viewport(0, 0, Width, Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // clear the screen

            textureProgram.UseProgram();                                               // use the texture program to display the 2d texture
            textureProgram.SetTexture(textureID);
            textureProgram.EnableAttributes();
            textureProgram.LoadBuffer(vertexBufferID); // load the positions so that it can use them to map to the UV coordinates
            GL.DrawArrays(PrimitiveType.Triangles, 0, vertexBufferData.Length);
            textureProgram.DisableAttributes();

            SwapBuffers();
        }
示例#2
0
        // for debugging
        private void RenderDepthToScreen()
        {
            OpenGLUtil.UseFrameBuffer(0); // now render to the screen
            GL.Viewport(0, 0, 512, 512);  // in the corner
            //GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // clear the screen

            textureProgram.UseProgram(); // use the texture program to display the 2d texture
            textureProgram.SetTexture(openGLLights[1].ShadowMapID);
            textureProgram.EnableAttributes();
            textureProgram.LoadBuffer(vertexBufferID); // load the positions so that it can use them to map to the UV coordinates
            OpenGLUtil.DisableTextureCompare(openGLLights[1].ShadowMapID);
            GL.DrawArrays(PrimitiveType.Triangles, 0, totalNumVerts);
            OpenGLUtil.EnableTextureCompare(openGLLights[1].ShadowMapID);
            textureProgram.DisableAttributes();
        }