public bool Render() { // Clear the buffer to begin the scene. D3D.BeginScene(0f, 0f, 0f, 1f); // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; // Rotate the world matrix by the rotation value so that the triangle will spin. Rotate(); // Construct the frustum. // Rotate the world matrix by the rotation value so that the triangle will spin. Matrix.RotationY(Rotation, out worldMatrix); // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. BumpMapModel.Render(D3D.DeviceContext); // Render the model using the color shader. if (!BumpMapShader.Render(D3D.DeviceContext, BumpMapModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, BumpMapModel.TextureCollection.Select(item => item.TextureResource).ToArray(), Light.Direction, Light.DiffuseColour)) { return(false); } // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
public bool Initialize(SystemConfiguration configuration, IntPtr windowHandle) { try { // Create the Direct3D object. D3D = new DX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { MessageBox.Show("Could not initialize Direct3D", "Error", MessageBoxButtons.OK); return(false); } // Create the camera object Camera = new Camera(); // Initialize a base view matrix the camera for 2D user interface rendering. Camera.SetPosition(0, 0, -10); Camera.Render(); var baseViewMatrix = Camera.ViewMatrix; // Create the model class. BumpMapModel = new BumpMapModel(); // Initialize the model object. if (!BumpMapModel.Initialize(D3D.Device, "sphere.txt", new[] { "stone01.dds", "bump01.dds" })) { MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK); return(false); } // Create the bump map shader object. BumpMapShader = new BumpMapShader(); // Initialize the bump map shader object. if (!BumpMapShader.Initialize(D3D.Device, windowHandle)) { MessageBox.Show("Could not initialize the light shader", "Error", MessageBoxButtons.OK); return(false); } // Create the light object. Light = new Light(); // Initialize the light object. Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f); Light.SetDiffuseColor(1, 1, 1, 1f); Light.SetDirection(0, 0, 1); Light.SetSpecularColor(0, 1, 1, 1); Light.SetSpecularPower(32); return(true); } catch (Exception ex) { MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'"); return(false); } }
public void Shutdown() { // Release the light object. Light = null; // Release the shader object. if (SpecMapShader != null) { SpecMapShader.Shuddown(); SpecMapShader = null; } // Release the model object. if (Model != null) { Model.Shutdown(); Model = null; } // Release the light shader object. if (BumpMapShader != null) { BumpMapShader.Shuddown(); BumpMapShader = null; } // Release the model object. if (BumpMapModel != null) { BumpMapModel.Shutdown(); BumpMapModel = null; } // Release the text object. if (Text != null) { Text.Shutdown(); Text = null; } // Release the camera object. if (Camera != null) { Camera = null; } // Release the Direct3D object. if (D3D != null) { D3D.Shutdown(); D3D = null; } }
public void Shutdown() { // Release the camera object. Camera = null; // Release the light object. Light = null; // Release the light shader object. BumpMapShader?.ShutDown(); BumpMapShader = null; // Release the model object. BumpMapModel?.Shutdown(); BumpMapModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void Shutdown() { // Release the fog shader object. if (FogShader != null) { FogShader.Shuddown(); FogShader = null; } // Release the texture shader object. if (TextureShader != null) { TextureShader.Shuddown(); TextureShader = null; } // Release the debug window object. if (DebugWindow != null) { DebugWindow.Shutdown(); DebugWindow = null; } // Release the render to texture object. if (RenderTexture != null) { RenderTexture.Shutdown(); RenderTexture = null; } // Release the light object. Light = null; // Release the shader object. if (LightShader != null) { LightShader.Shuddown(); LightShader = null; } // Release the model object. if (Model != null) { Model.Shutdown(); Model = null; } // Release the light shader object. if (BumpMapShader != null) { BumpMapShader.Shuddown(); BumpMapShader = null; } // Release the model object. if (BumpMapModel != null) { BumpMapModel.Shutdown(); BumpMapModel = null; } // Release the text object. if (Text != null) { Text.Shutdown(); Text = null; } // Release the camera object. if (Camera != null) { Camera = null; } // Release the Direct3D object. if (D3D != null) { D3D.Shutdown(); D3D = null; } }