Exemple #1
0
        public void Render()
        {
            Demo.OnHandleInput();
            Demo.OnUpdate();

            GL.UseProgram(shaderProgram);
            GL.Enable(EnableCap.DepthTest);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            _meshFactory.InitInstancedRender(Demo.World.CollisionObjectArray);
            _meshFactory.RenderInstanced(ref lookat);

            GL.UseProgram(0);
            if (Demo.IsDebugDrawEnabled)
            {
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadMatrix(ref lookat);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref perspective);
                (Demo.World.DebugDrawer as PhysicsDebugDraw).DrawDebugWorld(Demo.World);
            }

            info.OnRender(Demo.FramesPerSecond);

            glControl.SwapBuffers();
        }
        public void Render()
        {
            Demo.OnHandleInput();
            Demo.OnUpdate();

            GL.UseProgram(shaderProgram);
            GL.Enable(EnableCap.DepthTest);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            if (viewChanged)
            {
                GL.Viewport(0, 0, glControl.Width, glControl.Height);

                FreeLook freelook = Demo.Freelook;
                lookat = Matrix4.LookAt(MathHelper.Convert(freelook.Eye), MathHelper.Convert(freelook.Target), MathHelper.Convert(freelook.Up));
                GL.UniformMatrix4(viewMatrixLocation, false, ref lookat);

                Matrix4.CreatePerspectiveFieldOfView(FieldOfView, AspectRatio, 0.1f, FarPlane, out perspective);
                perspective *= Matrix4.CreateScale(-1.0f, 1.0f, 1.0f);
                GL.UniformMatrix4(projectionMatrixLocation, false, ref perspective);

                Vector3 lightPosition = new Vector3(30, 20, 10);
                GL.Uniform3(lightPositionVectorLocation, lightPosition);
                GL.Uniform3(eyePositionVectorLocation, MathHelper.Convert(freelook.Eye));

                if (CullingEnabled)
                {
                    GL.Enable(EnableCap.CullFace);
                }
                else
                {
                    GL.Disable(EnableCap.CullFace);
                }

                viewChanged = false;
            }

            if (Demo.World != null)
            {
                _meshFactory.InitInstancedRender(Demo.World.CollisionObjectArray);
                _meshFactory.RenderInstanced();
            }

            GL.UseProgram(0);
            if (Demo.IsDebugDrawEnabled)
            {
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadMatrix(ref lookat);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref perspective);
                (Demo.World.DebugDrawer as PhysicsDebugDraw).DrawDebugWorld(Demo.World);
            }

            info.OnRender(Demo.FramesPerSecond);

            glControl.SwapBuffers();
        }