Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }