public void Resize(IntPtr hwnd, int screenWidth, int screenHeight) { screenheight_ = screenHeight; screenwidth_ = screenWidth; SaveHeight = screenHeight; SaveWidth = screenWidth; _hwnd = hwnd; _Input.ScreenHeight = screenHeight; _Input.ScreenWidth = screenWidth; _Direct3D?.Shutdown(); _Direct3D = new D3DX(); if (!_Direct3D.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR)) { MessageBox.Show("Could not initialize DirectX 11.", "Error", MessageBoxButtons.OK); } _ColorShader?.Shutdown(); _ColorShader = new ColorShader(); if (!_ColorShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the color shader object.", "Error", MessageBoxButtons.OK); } _MonoShader?.Shutdown(); _MonoShader = new MonocolorShader(); if (!_MonoShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the monocolor shader object.", "Error", MessageBoxButtons.OK); } graph.terrain.ChangeDevice(_Direct3D); #region Axis graph.AxleX.ChangeDevice(_Direct3D.Device); graph.AxleY.ChangeDevice(_Direct3D.Device); graph.AxleZ.ChangeDevice(_Direct3D.Device); _AxisMini.ChangeDevice(_Direct3D.Device); #endregion #region Text CpuUsage_.ChangeDevice(_Direct3D.Device); FramesPerSecond_.ChangeDevice(_Direct3D.Device); IntersectionDebug_.ChangeDevice(_Direct3D.Device); SensivityZ_.ChangeDevice(_Direct3D.Device); GridDensity_.ChangeDevice(_Direct3D.Device); #endregion _DebugLine.ChangeDevice(_Direct3D.Device); foreach (var button in ButtonList) { button.ChangeDevice(_Direct3D.Device); } }
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); }
public bool Initialize(IntPtr hwnd, int screenWidth, int screenHeight, string path) { float cameraX, cameraY, cameraZ, rotX, rotY, rotZ; screenheight_ = screenHeight; screenwidth_ = screenWidth; SaveHeight = screenHeight; SaveWidth = screenWidth; _hwnd = hwnd; _Input = new Input(); if (!_Input.Initialize(screenWidth, screenHeight)) { MessageBox.Show("Could not initialize the input object.", "Error", MessageBoxButtons.OK); return(false); } _Direct3D = new D3DX(); if (!_Direct3D.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR)) { MessageBox.Show("Could not initialize DirectX 11.", "Error", MessageBoxButtons.OK); return(false); } _ColorShader = new ColorShader(); if (!_ColorShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the color shader object.", "Error", MessageBoxButtons.OK); return(false); } _MonoShader = new MonocolorShader(); if (!_MonoShader.Initialize(_Direct3D.Device)) { MessageBox.Show("Could not initialize the monocolor shader object.", "Error", MessageBoxButtons.OK); return(false); } graph = new Graph(); if (!graph.Initialize(_Direct3D, _DataHeader, _Data, path)) { MessageBox.Show("Could not initialize the graph object.", "Error", MessageBoxButtons.OK); return(false); } _AxisMini = new AxisRosette(); if (!_AxisMini.Initialize(_Direct3D, 30.0f)) { MessageBox.Show("Could not initialize the axis object.", "Error", MessageBoxButtons.OK); return(false); } #region Camera _Camera = new Camera { Position = new Vector3(0.0f, 0.0f, -1.0f) }; _Camera.Render(); _baseViewMatrix = _Camera._viewMatrix; cameraX = 0; cameraY = 0; cameraZ = 0; rotX = 0.0f; rotY = 0.0f; rotZ = 0.0f; _Camera.Position = new Vector3(cameraX, cameraY, cameraZ); _Camera.Rotation = new Vector3(rotX, rotY, rotZ); _Position = new Position(); _Position.SetPosition(cameraX, cameraY, cameraZ); _Position.SetRotation(rotX, rotY, rotZ); _Position.SetOffSet(graph.terrain.Width / 2.0f, 0, graph.terrain.Height / 2.0f); _Position.SetRadious(graph.terrain.Width / 2.0f); _Position.orbit = true; #endregion _Timer = new Timer(); if (!_Timer.Initialize()) { MessageBox.Show("Could not initialize the timer object.", "Error", MessageBoxButtons.OK); return(false); } //// Create the fps object. //_Fps = new FpsClass; //if (!_Fps) return false; //_Fps.Initialize(); //_Cpu = new CpuClass; //if (!_Cpu) return false; //_Cpu.Initialize(); if (!InitializeText()) { return(false); } _DebugLine = new VectorLine(); if (!_DebugLine.Initialize(_Direct3D.Device)) { return(false); } _DebugLine.Color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); if (!InitializeButtons()) { return(false); } //_RenderTexture = new RenderTexture(); //if (!_RenderTexture.Initialize(_Direct3D.Device, screenWidth, screenHeight)) return false; //_DebugWindow = new DebugWindowClass; //if (!_DebugWindow) return false; //result = _DebugWindow.Initialize(_Direct3D.GetDevice(), screenWidth, screenHeight, 100, 100); //if (!result) //{ // MessageBox.Show("Could not initialize the debug window object.", L"Error", MessageBoxButtons.OK); // return false; //} //_TextureShader = new TextureShaderClass; //if (!_TextureShader) return false; //result = _TextureShader.Initialize(_Direct3D.GetDevice(), hwnd); //if (!result) //{ // MessageBox.Show("Could not initialize the texture shader object.", L"Error", MessageBoxButtons.OK); // return false; //} return(true); }