private bool RenderSentence(DeviceContext deviceContext, DFontShader fontShader, DSentence sentence, Matrix worldMatrix, Matrix orthoMatrix) { // 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(sentence.VertexBuffer, stride, offset)); // Set the index buffer to active in the input assembler so it can be rendered. deviceContext.InputAssembler.SetIndexBuffer(sentence.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; // Create a pixel color vector with the input sentence color. var pixelColor = new Vector4(sentence.red, sentence.green, sentence.blue, 1); // Render the text using the font shader. if (!fontShader.Render(deviceContext, sentence.IndexCount, worldMatrix, BaseViewMatrix, orthoMatrix, Font.Texture.TextureResource, pixelColor)) { return(false); } return(true); }
// Methods public bool Initialize(SharpDX.Direct3D11.Device device, DeviceContext deviceContext, IntPtr windowHandle, int screanWidth, int screenHeight, Matrix baseViewMatrix) { // Store the screen width and height. ScreenWidth = screanWidth; ScreenHeight = screenHeight; // Store the base view matrix. BaseViewMatrix = baseViewMatrix; // Create the font object. Font = new DFont(); // Initialize the font object. if (!Font.Initialize(device, "fontdata.txt", "font.bmp")) { return(false); } // Create the font shader object. FontShader = new DFontShader(); // Initialize the font shader object. if (!FontShader.Initialize(device, windowHandle)) { return(false); } // Initialize the first sentence. if (!InitializeSentence(out sentences[0], 16, device)) { return(false); } // Now update the sentence vertex buffer with the new string information. if (!UpdateSentece(ref sentences[0], "FPS: ", 20, 20, 1, 1, 1, deviceContext)) { return(false); } // Initialize the second sentence. if (!InitializeSentence(out sentences[1], 16, device)) { return(false); } // Now update the sentence vertex buffer with the new string information. if (!UpdateSentece(ref sentences[1], "CPU: ", 20, 40, 1, 1, 0, deviceContext)) { return(false); } return(true); }
public bool Render(DeviceContext deviceContext, DFontShader fontShader, Matrix worldMatrix, Matrix orthoMatrix) { // Render all Sentances however many there mat be. foreach (DSentence sentance in sentences) { if (!RenderSentence(deviceContext, fontShader, sentance, worldMatrix, orthoMatrix)) { return(false); } } return(true); }
public void Shutdown() { // Release all sentances however many there may be. foreach (DSentence sentance in sentences) { ReleaseSentences(sentance); } // Release the font shader object. FontShader?.Shuddown(); FontShader = null; // Release the font object. Font?.Shutdown(); Font = null; }
// 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 camera object Camera = new DCamera(); // Initialize a base view matrix with the camera for 2D user interface rendering. Camera.SetPosition(0.0f, 0.0f, -1.0f); Camera.Render(); Matrix baseViewMatrix = Camera.ViewMatrix; // Set the initial position of the camera. (Since the ViewMatrix is already created from a base position.) Camera.SetPosition(50.0f, 2.0f, -7.0f); // Create the model object. TerrainModel = new DTerrain(); // Initialize the terrain object. if (!TerrainModel.Initialize(D3D.Device, "heightmap01.bmp")) { return(false); } // Create the position object. Position = new DPosition(); // Set the initial position of the viewer to the same as the initial camera position. Position.SetPosition(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z); // Create the fps object. FPS = new DFPS(); // Initialize the fps object. FPS.Initialize(); // Create the cpu object. CPU = new DCPU(); // Initialize the cpu object. CPU.Initialize(); // Create the font shader object. FontShader = new DFontShader(); // Initialize the font shader object. if (!FontShader.Initialize(D3D.Device, windowHandle)) { return(false); } // Create the text object. Text = new DText(); // Initialize the text object. if (!Text.Initialize(D3D.Device, D3D.DeviceContext, windowHandle, configuration.Width, configuration.Height, baseViewMatrix)) { return(false); } // Set the video card information in the text object. if (!Text.SetVideoCard(D3D.VideoCardDescription, D3D.VideoCardMemory, D3D.DeviceContext)) { return(false); } // Create the color shader object. TerrainShader = new DTerrainShader(); // Initialize the color shader object. if (!TerrainShader.Initialize(D3D.Device, windowHandle)) { return(false); } // Create the light object. Light = new DLight(); // Initialize the light object. Light.SetAmbientColor(0.05f, 0.05f, 0.05f, 1.0f); Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); Light.Direction = new Vector3(0.0f, 0.0f, 0.75f); return(true); } catch (Exception ex) { MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'"); return(false); } }
// Methods public bool Initialize(SharpDX.Direct3D11.Device device, DeviceContext deviceContext, IntPtr windowHandle, int screanWidth, int screenHeight, Matrix baseViewMatrix) { // Store the screen width and height. ScreenWidth = screanWidth; ScreenHeight = screenHeight; // Store the base view matrix. BaseViewMatrix = baseViewMatrix; // Create the font object. Font = new DFont(); // Initialize the font object. if (!Font.Initialize(device, "fontdata.txt", "font.bmp")) { return(false); } // Create the font shader object. FontShader = new DFontShader(); // Initialize the font shader object. if (!FontShader.Initialize(device, windowHandle)) { return(false); } // Initialize the first sentence. if (!InitializeSentence(out sentences[0], 150, 20, device)) { return(false); } // Initialize the second sentence. if (!InitializeSentence(out sentences[1], 32, 40, device)) { return(false); } // Initialize the third sentence. if (!InitializeSentence(out sentences[2], 16, 70, device)) { return(false); } // Initialize the fourth sentence. if (!InitializeSentence(out sentences[3], 16, 90, device)) { return(false); } // Initialize the Fifth sentence. if (!InitializeSentence(out sentences[4], 16, 120, device)) { return(false); } // Initialize the Sixth sentence. if (!InitializeSentence(out sentences[5], 16, 140, device)) { return(false); } // Initialize the Seventh sentence. if (!InitializeSentence(out sentences[6], 16, 160, device)) { return(false); } // Initialize the Eighth sentence. if (!InitializeSentence(out sentences[7], 16, 190, device)) { return(false); } // Initialize the Eighth sentence. if (!InitializeSentence(out sentences[8], 16, 210, device)) { return(false); } // Initialize the Eighth sentence. if (!InitializeSentence(out sentences[9], 16, 230, device)) { return(false); } // Initialize the Eighth sentence. if (!InitializeSentence(out sentences[10], 32, 260, device)) { return(false); } // Initialize the Eighth sentence. if (!InitializeSentence(out sentences[11], 32, 290, device)) { return(false); } return(true); }