private bool RenderSentence(DeviceContext deviceContext, DShaderManager shaderManager, Matrix worldMatrix, Matrix viewMatrix, Matrix orthoMatrix, ShaderResourceView fontTexture) { // Set vertex buffer stride and offset. var stride = Utilities.SizeOf <DFont.DVertexType>(); var offset = 0; // Set the vertex buffer to active in the input assembler so it can be rendered. deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, stride, offset)); // Set the index buffer to active in the input assembler so it can be rendered. deviceContext.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0); // Set the type of the primitive that should be rendered from this vertex buffer, in this case triangles. deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; shaderManager.RenderFontShader(deviceContext, IndexCount, worldMatrix, viewMatrix, orthoMatrix, fontTexture, PixelColour); return(true); }
public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) { // Create the input object. The input object will be used to handle reading the keyboard and mouse input from the user. Input = new DInput(); // Initialize the input object. if (!Input.Initialize(configuration, windowHandle)) { return(false); } // Create the Direct3D object. D3D = new DDX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { return(false); } // Create the shader manager object. ShaderManager = new DShaderManager(); // Initialize the shader manager object. if (!ShaderManager.Initilize(D3D, windowHandle)) { return(false); } // Create and initialize Timer. Timer = new DTimer(); if (!Timer.Initialize()) { return(false); } // Create the fps object. FPS = new DFPS(); FPS.Initialize(); // Create and Initialize the Zone object. Zone = new DZone(); if (!Zone.Initialze(D3D, windowHandle, configuration)) { return(false); } return(true); }
public bool Render(DDX11 D3DDevice, DShaderManager shaderManager, Matrix worldMatrix, Matrix baseViewMatrix, Matrix orthoMatrix) { // Turn off the Z buffer and enable alpha blending to begin 2D rendering. D3DDevice.TurnZBufferOff(); D3DDevice.TurnOnAlphaBlending(); // Render the fps string. FpsString.Render(D3DDevice.DeviceContext, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix, Font1.Texture.TextureResource); // Render the position and rotation strings. foreach (DText position in PositionStrings) { position.Render(D3DDevice.DeviceContext, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix, Font1.Texture.TextureResource); } // Render the video card strings. foreach (DText vidString in VideoStrings) { vidString.Render(D3DDevice.DeviceContext, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix, Font1.Texture.TextureResource); } // Render the render count strings. foreach (DText renderString in RenderCountStrings) { renderString.Render(D3DDevice.DeviceContext, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix, Font1.Texture.TextureResource); } // Turn off alpha blending now that the text has been rendered. D3DDevice.TurnOffAlphaBlending(); if (!MiniMap.Render(D3DDevice.DeviceContext, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix)) { return(false); } // Turn the Z buffer back on now that the 2D rendering has completed. D3DDevice.TurnZBufferOn(); return(true); }
public bool Frame(DDX11 direct3D, DInput input, DShaderManager shaderManager, DTextureManager textureManager, float frameTime, int fps) { // Do the frame input processing. if (!HandleInput(input, frameTime)) { return(false); } // Do the frame processing for the user interface. if (!UserInterface.Frame(direct3D.DeviceContext, fps, Position.PositionX, Position.PositionY, Position.PositionZ, Position.RotationX, Position.RotationY, Position.RotationZ)) { return(false); } // Render the graphics. if (!Render(direct3D, shaderManager, textureManager)) { return(false); } return(true); }
public bool Frame(DDX11 direct3D, DInput input, DShaderManager shaderManager, DTextureManager textureManager, float frameTime, int fps) { // Do the frame input processing. if (!HandleInput(input, frameTime)) { return(false); } // Do the frame processing for the user interface. if (!UserInterface.Frame(direct3D.DeviceContext, fps, Position.PositionX, Position.PositionY, Position.PositionZ, Position.RotationX, Position.RotationY, Position.RotationZ)) { return(false); } // Do the terrain frame processing. Terrain.Frame(); float height = 99.0f; // If the height is locked to the terrain then position the camera on top of it. if (HeightLocked) { Terrain.GetHeightAtPosition(Position.PositionX, Position.PositionZ, out height); } Position.SetPosition(Position.PositionX, height + 1.0f, Position.PositionZ); Camera.SetPosition(Position.PositionX, height + 1.0f, Position.PositionZ); // Render the graphics. if (!Render(direct3D, shaderManager, textureManager)) { return(false); } return(true); }
public bool Render(DDX11 direct3D, DShaderManager shaderManager) { // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and projection matrices from the camera and d3d objects. Matrix worldMatrix = direct3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = direct3D.ProjectionMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix orthoMatrix = direct3D.OrthoMatrix; // Clear the buffers to begin the scene. direct3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Render the terrain grid using the color shader. Terrain.Render(direct3D.DeviceContext); if (!shaderManager.RenderColorShader(direct3D.DeviceContext, Terrain.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix)) { return(false); } // Render the user interface. if (DisplayUI) { if (!UserInterface.Render(direct3D, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix)) { return(false); } } // Present the rendered scene to the screen. direct3D.EndScene(); return(true); }
public bool Render(DDX11 direct3D, DShaderManager shaderManager, DTextureManager textureManager) { // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and projection matrices from the camera and d3d objects. Matrix worldMatrix = direct3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = direct3D.ProjectionMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix orthoMatrix = direct3D.OrthoMatrix; // Clear the buffers to begin the scene. direct3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Turn off back face culling and turn off the Z buffer. direct3D.TurnOffCulling(); direct3D.TurnZBufferOff(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z, out worldMatrix); // Render the sky dome using the sky dome shader. SkyDomeModel.Render(direct3D.DeviceContext); if (!shaderManager.RenderSkyDomeShader(direct3D.DeviceContext, SkyDomeModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDomeModel.m_apexColor, SkyDomeModel.m_centerColor)) { return(false); } // Reset the world matrix. worldMatrix = direct3D.WorldMatrix; // Turn the Z buffer back and back face culling on. direct3D.TurnZBufferOn(); direct3D.TurnOnCulling(); // Turn on wire frame rendering of the terrain if needed. if (WireFrame) { direct3D.EnableWireFrame(); } // Render the terrain grid using the color shader. Terrain.Render(direct3D.DeviceContext); if (!shaderManager.RenderTerrainShader(direct3D.DeviceContext, Terrain.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, textureManager.TextureArray[0].TextureResource, textureManager.TextureArray[1].TextureResource, Light.Direction, Light.DiffuseColour)) { return(false); } // Turn off wire frame rendering of the terrain if it was on. if (WireFrame) { direct3D.DisableWireFrame(); } // Render the user interface. if (DisplayUI) { if (!UserInterface.Render(direct3D, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix)) { return(false); } } // Present the rendered scene to the screen. direct3D.EndScene(); return(true); }
public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) { // Create the input object. The input object will be used to handle reading the keyboard and mouse input from the user. Input = new DInput(); // Initialize the input object. if (!Input.Initialize(configuration, windowHandle)) { return(false); } // Create the Direct3D object. D3D = new DDX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { return(false); } // Create the shader manager object. ShaderManager = new DShaderManager(); // Initialize the shader manager object. if (!ShaderManager.Initilize(D3D, windowHandle)) { return(false); } // Create the texture manager object. TextureManager = new DTextureManager(); // Initialize the texture manager object. if (!TextureManager.Initialize(10)) { return(false); } // Load textures into the texture manager. if (!TextureManager.LoadTexture(D3D.Device, D3D.DeviceContext, "rock01d.bmp", 0)) { return(false); } if (!TextureManager.LoadTexture(D3D.Device, D3D.DeviceContext, "rock01n.bmp", 1)) { return(false); } if (!TextureManager.LoadTexture(D3D.Device, D3D.DeviceContext, "snow01n.bmp", 2)) { return(false); } // Create and initialize Timer. Timer = new DTimer(); if (!Timer.Initialize()) { return(false); } // Create the fps object. FPS = new DFPS(); FPS.Initialize(); // Create and Initialize the Zone object. Zone = new DZone(); if (!Zone.Initialze(D3D, windowHandle, configuration)) { return(false); } return(true); }
// Methods. public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) { try { #region Initialize System // Create the Direct3D object. D3D = new DDX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { return(false); } // Create the shader manager object. ShaderManager = new DShaderManager(); // Initialize the shader manager object. if (!ShaderManager.Initialize(D3D.Device, windowHandle)) { return(false); } #endregion #region Initialize Camera // Create the camera object Camera = new DCamera(); // Set the initial position and rotation of the camera. Camera.SetPosition(0.0f, 0.0f, -10.0f); #endregion #region Data variables. // Create the light object. Light = new DLight(); // Initialize the light object. Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f); Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); Light.Direction = new Vector3(0.0f, 0.0f, 1.0f); Light.SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f); Light.SetSpecularPower(64.0f); #endregion #region Initialize Models // Create the ground model object. CubeModel1 = new DModel(); // Initialize the cube model object. if (!CubeModel1.Initialize(D3D.Device, "cube.txt", "marble.bmp")) { return(false); } // Create the second model object. CubeModel2 = new DModel(); // Initialize the cube model object. if (!CubeModel2.Initialize(D3D.Device, "cube.txt", "metal.bmp")) { return(false); } // Create the third bump model object for models with normal maps and related vectors. CubeBumpMapModel3 = new DBumpMapModel(); // Initialize the bump model object. if (!CubeBumpMapModel3.Initialize(D3D.Device, "cube.txt", "stone01.bmp", "normal.bmp")) { return(false); } #endregion return(true); } catch (Exception ex) { MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'"); return(false); } }
public bool Render(DDX11 direct3D, DShaderManager shaderManager, DTextureManager textureManager) { // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, and projection matrices from the camera and d3d objects. Matrix worldMatrix = direct3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = direct3D.ProjectionMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix orthoMatrix = direct3D.OrthoMatrix; // Construct the frustum. Frustum.ConstructFrustum(projectionMatrix, viewCameraMatrix); // Clear the buffers to begin the scene. direct3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Turn off back face culling and turn off the Z buffer. direct3D.TurnOffCulling(); direct3D.TurnZBufferOff(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z, out worldMatrix); // Render the sky dome using the sky dome shader. SkyDomeModel.Render(direct3D.DeviceContext); if (!shaderManager.RenderSkyDomeShader(direct3D.DeviceContext, SkyDomeModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDomeModel.m_apexColor, SkyDomeModel.m_centerColor)) { return(false); } // Reset the world matrix. worldMatrix = direct3D.WorldMatrix; // Turn the Z buffer back and back face culling on. direct3D.TurnZBufferOn(); direct3D.TurnOnCulling(); // Turn on wire frame rendering of the terrain if needed. if (WireFrame) { direct3D.EnableWireFrame(); } // Render the terrain cells (and cell lines if needed). for (int i = 0; i < Terrain.m_CellCount; i++) { // Render each terrain cell if it is visible only. if (Terrain.RenderCell(direct3D.DeviceContext, i, Frustum)) { // Render the cell buffers using the terrain shader. if (!shaderManager.RenderTerrainShader(direct3D.DeviceContext, Terrain.GetCellIndexCount(i), worldMatrix, viewCameraMatrix, projectionMatrix, textureManager.TextureArray[0].TextureResource, textureManager.TextureArray[1].TextureResource, Light.Direction, Light.DiffuseColour)) { return(false); } // If needed then render the bounding box around this terrain cell using the color shader. if (CellLines) { Terrain.RenderCellLines(direct3D.DeviceContext, i); if (!shaderManager.RenderColorShader(direct3D.DeviceContext, Terrain.GetCellLinesIndexCount(i), worldMatrix, viewCameraMatrix, projectionMatrix)) { return(false); } } } } // Turn off wire frame rendering of the terrain if it was on. if (WireFrame) { direct3D.DisableWireFrame(); } // Update the render counts in the UI. if (!UserInterface.UpdateRenderCountStrings(Terrain.m_renderCount, Terrain.m_cellsDrawn, Terrain.m_cellsCulled, direct3D.DeviceContext)) { return(false); } // Render the user interface. if (DisplayUI) { if (!UserInterface.Render(direct3D, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix)) { return(false); } } // Present the rendered scene to the screen. direct3D.EndScene(); return(true); }
// Methods. public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) { try { // Create the input object. The input object will be used to handle reading the keyboard and mouse input from the user. Input = new DInput(); // Initialize the input object. if (!Input.Initialize(configuration, windowHandle)) { return(false); } // #region Initialize System // Create the Direct3D object. D3D = new DDX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { return(false); } // Create the shader manager object. ShaderManager = new DShaderManager(); // Initialize the shader manager object. if (!ShaderManager.Initilize(D3D, windowHandle)) { return(false); } // Create the position object. Position = new DPosition(); // Set the initial position and rotation of the viewer. Position.SetPosition(0.0f, 1.5f, -4.0f); Position.SetRotation(15.0f, 0.0f, 0.0f); // Create the camera object Camera = new DCamera(); // Initialize a base view matrix with the camera for 2D user interface rendering. Camera.SetPosition(0.0f, 0.0f, -10.0f); Camera.Render(); Camera.RenderBaseViewMatrix(); // Create the fps object. FPS = new DFPS(); //// Initialize the fps object. FPS.Initialize(); // Create the user interface object. UserInterface = new DUserInterface(); // Initialize the user interface object. if (!UserInterface.Initialize(D3D, configuration)) { return(false); } // Create the ground model object. GroundModel = new DModel(); // Initialize the ground model object. if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "rock015.bmp")) { return(false); } // Create the foliage object. Foliage = new DFoliage(); // Initialize the foliage object. if (!Foliage.Initialize(D3D.Device, "grass01.bmp", 500)) { return(false); } return(true); } catch (Exception ex) { MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'"); return(false); } }