private bool RenderSceneToFile() { var direct3D = new D3DX(); if (!direct3D.Initialize(SaveWidth, SaveHeight, VSYNC_ENABLED, _hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR)) { MessageBox.Show("Could not initialize DirectX 11.", "Error", MessageBoxButtons.OK); return(false); } var colorShader = new ColorShader(); if (!colorShader.Initialize(direct3D.Device)) { MessageBox.Show("Could not initialize the color shader object.", "Error", MessageBoxButtons.OK); return(false); } var monocolorShader = new MonocolorShader(); if (!monocolorShader.Initialize(direct3D.Device)) { MessageBox.Show("Could not initialize the monocolor shader object.", "Error", MessageBoxButtons.OK); return(false); } var graph = new Graph(in this.graph, direct3D.Device); direct3D.SetBackBufferRenderTarget(); direct3D.BeginScene(BackgroundColour); #region Render _Camera.Render(); var worldMatrix = direct3D.WorldMatrix; var viewMatrix = _Camera._viewMatrix; var projectionMatrix = direct3D.ProjectionMatrix; var rotation = _Camera.Rotation; direct3D.TurnOnAlphaBlending(); if (!graph.Render(direct3D, colorShader, monocolorShader, worldMatrix, viewMatrix, projectionMatrix, rotation)) { return(false); } #endregion SaveToFile(direct3D, direct3D.BackBuffer, SharpDX.WIC.PixelFormat.Format32bppRGB); graph.Dispose(); colorShader.Shutdown(); monocolorShader.Shutdown(); direct3D.Shutdown(); return(true); }
private bool RenderGraphics() //todo: refactor { bool result = true; if (PrintScreen) { PrintScreen = false; if (!RenderSceneToFile()) { return(false); } } _Direct3D.BeginScene(BackgroundColour); // Render the scene as normal to the back buffer. //result = RenderScene(); //if (!result) return false; _Camera.Render(); var worldMatrix = _Direct3D.WorldMatrix; var viewMatrix = _Camera._viewMatrix; var projectionMatrix = _Direct3D.ProjectionMatrix; var orthoMatrix = _Direct3D.OrthoMatrix; var rotation = _Camera.Rotation; _Direct3D.TurnOnAlphaBlending(); var deviceContext = _Direct3D.DeviceContext; graph.Render(_Direct3D, _ColorShader, _MonoShader, worldMatrix, viewMatrix, projectionMatrix, rotation); if (!_DebugLine.Render(deviceContext, _MonoShader, worldMatrix, viewMatrix, projectionMatrix)) { return(false); } _Direct3D.TurnZBufferOff(); foreach (var button in ButtonList) { result &= button.Render(_Direct3D, _MonoShader, worldMatrix, _baseViewMatrix, orthoMatrix); } if (!result) { return(false); } if (_RenderMiniAxis) { var worldMatrixPlaine = worldMatrix; var transformMatrix = Matrix.RotationY(-rotation.Y * (float)(Math.PI / 180f)); worldMatrixPlaine = Matrix.Multiply(worldMatrixPlaine, transformMatrix); transformMatrix = Matrix.RotationX(-rotation.X * (float)(Math.PI / 180f)); worldMatrixPlaine = Matrix.Multiply(worldMatrixPlaine, transformMatrix); transformMatrix = Matrix.Translation(screenwidth_ / 2 - 35, 0, 30); worldMatrixPlaine = Matrix.Multiply(worldMatrixPlaine, transformMatrix); _AxisMini.Render(deviceContext, _MonoShader, worldMatrixPlaine, _baseViewMatrix, orthoMatrix); } //result = _DebugWindow.Render(_Direct3D.GetDeviceContext(), 50, 50); //if (!result) return false; //// Render the debug window using the texture shader. //result = _TextureShader.Render(_Direct3D.GetDeviceContext(), _DebugWindow.GetIndexCount(), worldMatrix, _baseViewMatrix, // orthoMatrix, _RenderTexture.GetShaderResourceView()); //if (!result) //{ // return false; //} _Direct3D.TurnOffAlphaBlending(); _Direct3D.TurnZBufferOn(); _Direct3D.EndScene(); return(true); }