/// <summary> /// Called when it is time to draw a frame. /// </summary> public override void Draw() { // Clears the background Display.ClearBuffers(); // Aplly a rotation Matrix4 mvp = Matrix4.CreateRotationY(Yaw) * ModelViewMatrix * ProjectionMatrix; Display.Shader = Shader; // Uniforms Shader.SetUniform("modelview", mvp); Shader.SetUniform("DiffuseMaterial", new float[] { 0.0f, 0.75f, 0.75f }); Shader.SetUniform("LightPosition", new float[] { 0.25f, 0.25f, -1.0f }); Shader.SetUniform("AmbientMaterial", new float[] { 0.04f, 0.04f, 0.04f }); Shader.SetUniform("SpecularMaterial", new float[] { 0.5f, 0.5f, 0.5f }); Shader.SetUniform("Shininess", 50.0f); if (swap) { Torus.Draw(); } else { Trefoil.Draw(); } // Some dummy text Sprite.Begin(); Sprite.DrawString(Font, new Vector2(50, 25), Color.White, "Here's an example of draw buffers."); Sprite.DrawString(Font, new Vector2(50, 50), Color.White, "Press space key to swap mesh."); Sprite.End(); }
/// <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(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(SkyColor); GraphicsDevice.BlendState = BlendState.AlphaBlend; GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; if (wireframeMode) { RasterizerState rasterizerState = new RasterizerState(); rasterizerState.FillMode = FillMode.WireFrame; GraphicsDevice.RasterizerState = rasterizerState; } else { GraphicsDevice.RasterizerState = RasterizerState.CullNone; } light.Draw(GraphicsDevice, Camera); teapot.Draw(GraphicsDevice, Camera); //cube.Draw(GraphicsDevice, Camera); geomCube.Draw(GraphicsDevice, Camera); geomCylinder.Draw(GraphicsDevice, Camera); geomSphere.Draw(GraphicsDevice, Camera); geomTorus.Draw(GraphicsDevice, Camera); floor.Draw(GraphicsDevice, Camera); DrawGrid(); DrawDebugOverlay(); Console.Draw(spriteBatch); base.Draw(gameTime); }
/// <summary> /// Called when it is time to draw a frame. /// </summary> public override void Draw() { // Clears the background Display.ClearBuffers(); Vector3 target = Vector3.Add(CameraPostion, new Vector3(0.0f, 0.0f, -1.0f)); Vector4 lightPos = new Vector4(0.0f, 1.0f, 0.0f, 0.0f); Vector4 diffuseColor = new Vector4(0.0f, 0.0f, 1.0f, 1.0f); // Bind the shader and the texture Display.Shader = Shader; Shader.SetUniform("textureUnit0", 0); Shader.SetUniform("diffuseColor", diffuseColor); #region Mirror // ModelViewProjection matrix ModelViewMatrix = Matrix4.CreateTranslation(0.0f, 1.7f, 0.0f) * Matrix4.Scale(1.0f, -1.0f, 1.0f) * Matrix4.LookAt(CameraPostion, target, Vector3.UnitY); Matrix4 mvp = ModelViewMatrix * ProjectionMatrix; Shader.SetUniform("mvMatrix", ModelViewMatrix); // Tranform light position Shader.SetUniform("lightPosition", Vector4.Transform(lightPos, ModelViewMatrix)); Display.RenderState.FrontFace = FrontFace.ClockWise; Display.Texture = Mars; Shader.SetUniform("mvpMatrix", Torus.Matrix * mvp); Shader.SetUniform("color", new Vector4(1.0f, 1.0f, 1.0f, 1.0f)); Torus.Draw(); Display.Texture = Moon; Shader.SetUniform("mvpMatrix", Matrix4.CreateTranslation(Sphere.Position) * Matrix4.CreateRotationY(Sphere.Rotation.Y) * mvp); Sphere.Draw(); Display.RenderState.FrontFace = FrontFace.CounterClockWise; #endregion #region Normal view ModelViewMatrix = Matrix4.LookAt(CameraPostion, target, Vector3.UnitY); mvp = ModelViewMatrix * ProjectionMatrix; // Tranform light position Shader.SetUniform("lightPosition", Vector4.Transform(lightPos, ModelViewMatrix)); Display.RenderState.Blending = true; Display.BlendingFunction(BlendingFactorSource.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); Display.Texture = Marble; Shader.SetUniform("mvpMatrix", Floor.Matrix * mvp); Shader.SetUniform("color", new Vector4(1.0f, 1.0f, 1.0f, 0.75f)); Floor.Draw(); Display.RenderState.Blending = false; Shader.SetUniform("color", new Vector4(1.0f, 1.0f, 1.0f, 1.0f)); Display.Texture = Mars; Shader.SetUniform("mvpMatrix", Torus.Matrix * mvp); Torus.Draw(); Display.Texture = Moon; Shader.SetUniform("mvpMatrix", Matrix4.CreateTranslation(Sphere.Position) * Matrix4.CreateRotationY(Sphere.Rotation.Y) * mvp); Sphere.Draw(); #endregion Batch.Begin(); Batch.DrawString(Font, new Vector2(10, 50), Color.White, "Camera position : {0}", CameraPostion.ToString()); Batch.End(); }