/// <summary> /// Called when it is time to draw a frame. /// </summary> public override void Draw() { // Clears the background Display.ClearBuffers(); Display.Shader = SceneShader; // Draws with the index buffer SceneShader.SetUniform("modelview_matrix", ModelViewMatrix); SceneShader.SetUniform("projection_matrix", ProjectionMatrix); Vector3 Position = new Vector3(0.0f, 0.0f, -5.0f); SceneShader.SetUniform("mvp_matrix", Matrix4.CreateTranslation(Position) * ModelViewMatrix * ProjectionMatrix); Plane.Draw(); SceneShader.SetUniform("mvp_matrix", Matrix4.CreateRotationY(Yaw) * ModelViewMatrix * ProjectionMatrix); Torus.Draw(); // Some dummy text SpriteBatch.Begin(); SpriteBatch.DrawString(Font, new Vector2(10, 15), Color.White, "Here's an example of shadow mapping."); SpriteBatch.End(); }
/// <summary> /// Loads contents /// </summary> public override void LoadContent() { Display.RenderState.ClearColor = Color.CornflowerBlue; Display.RenderState.DepthTest = true; #region Mesh //Mesh = PlyLoader.LoadPly("data/bunny.ply"); Torus = Mesh.CreateTorus(0.5f, 1.0f, 32, 32); Plane = Mesh.CreatePlane(10.0f); #endregion #region Shader SceneShader = Shader.CreateFromFile("shaders/scene.vert", "shaders/scene.frag"); SceneShader.Compile(); #endregion #region Font SpriteBatch = new SpriteBatch(); Font = BitmapFont.CreateFromTTF(@"c:\windows\fonts\verdana.ttf", 10, FontStyle.Regular); #endregion // Frame buffer FrameBuffer = new FrameBuffer(new Size(512, 512)); Camera = new Vector3(-5.0f, 5.0f, 10.0f); Light = new Vector3(0.0f, 0.0f, 10.0f); // Matrices ModelViewMatrix = Matrix4.LookAt(Camera, Vector3.Zero, Vector3.UnitY); float aspectRatio = (float)Display.ViewPort.Width / (float)Display.ViewPort.Height; ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(40.0f), aspectRatio, 1.0f, 100.0f); // Rotation Yaw = 0.0f; }
/// <summary> /// Unload contents /// </summary> public override void UnloadContent() { if (Plane != null) { Plane.Dispose(); } Plane = null; if (Torus != null) { Torus.Dispose(); } Torus = null; if (SceneShader != null) { SceneShader.Dispose(); } SceneShader = null; if (Font != null) { Font.Dispose(); } Font = null; if (SpriteBatch != null) { SpriteBatch.Dispose(); } SpriteBatch = null; if (FrameBuffer != null) { FrameBuffer.Dispose(); } FrameBuffer = null; }