public void Shutdown()
        {
            // Release the light object.
            Light  = null;
            Light2 = null;
            // Release the camera object.
            Camera = null;

            // Release the second render to texture object.
            RenderTexture2?.Shutdown();
            RenderTexture2 = null;
            // Release the shadow shader object.
            ShadowShader?.ShutDown();
            ShadowShader = null;
            // Release the depth shader object.
            DepthShader?.ShutDown();
            DepthShader = null;
            /// Release the render to texture object.
            RenderTexture?.Shutdown();
            RenderTexture = null;
            // Release the ground model object.
            GroundModel?.Shutdown();
            GroundModel = null;
            // Release the sphere model object.
            SphereModel?.Shutdown();
            SphereModel = null;
            // Release the cube model object.
            CubeModel?.Shutdown();
            CubeModel = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
        public void ShutDown()
        {
            DPerfLogger.ShutDown();

            // Release the light object.
            Light = null;
            // Release the position object.
            Position = null;
            // Release the timer object.
            Timer = null;
            // Release the camera object.
            Camera = null;

            // Release the shadow shader object.
            ShadowShader?.ShutDown();
            ShadowShader = null;
            // Release the transparent depth shader object.
            TransparentDepthShader?.ShutDown();
            TransparentDepthShader = null;
            // Release the depth shader object.
            DepthShader?.ShutDown();
            DepthShader = null;
            // Release the render to texture object.
            RenderTexture?.Shutdown();
            RenderTexture = null;
            // Release the tree object.
            TreeModel?.Shutdown();
            TreeModel = null;
            // Release the model object.
            GroundModel?.Shutdown();
            GroundModel = null;
            // Release the input object.
            Input?.Shutdown();
            Input = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
        // 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);
                }
                #endregion

                #region Initialize Camera
                // Create the camera object
                Camera = new DCamera();

                // Set the initial position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                #endregion

                #region Initialize Models
                // Create the cube model object.
                CubeModel = new DModel();

                // Initialize the cube model object.
                if (!CubeModel.Initialize(D3D.Device, "cube.txt", "wall01.bmp"))
                {
                    return(false);
                }

                // Set the position for the cube model.
                CubeModel.SetPosition(-2.0f, 2.0f, 0.0f);

                // Create the sphere model object.
                SphereModel = new DModel();

                // Initialize the sphere model object.
                if (!SphereModel.Initialize(D3D.Device, "sphere.txt", "ice01.bmp"))
                {
                    return(false);
                }

                // Set the position for the sphere model.
                SphereModel.SetPosition(2.0f, 2.0f, 0.0f);

                // Create the ground model object.
                GroundModel = new DModel();

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "metal001.bmp"))
                {
                    return(false);
                }

                // Set the position for the ground model.
                GroundModel.SetPosition(0.0f, 1.0f, 0.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.SetLookAt(0.0f, 0.0f, 0.0f);
                Light.GenerateProjectionMatrix();

                // Create the second light object.
                Light2 = new DLight();
                // Initialize the second light object.
                Light2.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
                Light2.SetLookAt(0.0f, 0.0f, 0.0f);
                Light2.GenerateProjectionMatrix();

                // Set the position of the first & second lights.
                Light.Position  = new Vector3(5.0f, 3.0f, -2.0f);
                Light2.Position = new Vector3(-5.0f, 3.0f, -2.0f);

                // Create the render to texture object.
                RenderTexture = new DRenderTexture();

                // Initialize the render to texture object.
                if (!RenderTexture.Initialize(D3D.Device, configuration))
                {
                    return(false);
                }

                // Create the second render to texture object.
                RenderTexture2 = new DRenderTexture();

                // Initialize the second render to texture object.
                if (!RenderTexture2.Initialize(D3D.Device, configuration))
                {
                    return(false);
                }
                #endregion

                #region Initialize Shaders
                // Create the depth shader object.
                DepthShader = new DDepthShader();

                // Initialize the depth shader object.
                if (!DepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the shadow shader object.
                ShadowShader = new DShadowShader();

                // Initialize the shadow shader object.
                if (!ShadowShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #4
0
        // 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);
                }
                #endregion

                #region Initialize Camera
                // Create the camera object
                Camera = new DCamera();

                // Set the initial position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                Camera.RenderBaseViewMatrix();
                #endregion

                #region Initialize Models
                // Create the cube model object.
                CubeModel = new DModel();

                // Initialize the cube model object.
                if (!CubeModel.Initialize(D3D.Device, "cube.txt", "wall01.bmp"))
                {
                    return(false);
                }

                // Set the position for the cube model.
                CubeModel.SetPosition(-2.0f, 2.0f, 0.0f);

                // Create the sphere model object.
                SphereModel = new DModel();

                // Initialize the sphere model object.
                if (!SphereModel.Initialize(D3D.Device, "sphere.txt", "ice01.bmp"))
                {
                    return(false);
                }

                // Set the position for the sphere model.
                SphereModel.SetPosition(2.0f, 2.0f, 0.0f);

                // Create the ground model object.
                GroundModel = new DModel();

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "metal001.bmp"))
                {
                    return(false);
                }

                // Set the position for the ground model.
                GroundModel.SetPosition(0.0f, 1.0f, 0.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.SetLookAt(0.0f, 0.0f, 0.0f);
                Light.GenerateProjectionMatrix();

                // Create the render to texture object.
                RenderTexture = new DRenderTexture();

                // Initialize the render to texture object.
                if (!RenderTexture.Initialize(D3D.Device, 1024, 1024, DSystemConfiguration.ScreenDepth, DSystemConfiguration.ScreenNear))
                {
                    return(false);
                }

                // Create the depth shader object.
                DepthShader = new DDepthShader();

                // Initialize the depth shader object.
                if (!DepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the black and white render to texture object.
                BlackWhiteRenderTexture = new DRenderTexture();

                // Initialize the black and white render to texture object.
                if (!BlackWhiteRenderTexture.Initialize(D3D.Device, 1024, 1024, DSystemConfiguration.ScreenDepth, DSystemConfiguration.ScreenNear))
                {
                    return(false);
                }
                #endregion

                #region Initialize Shaders
                // Create the shadow shader object.
                ShadowShader = new DShadowShader();

                // Initialize the shadow shader object.
                if (!ShadowShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Set the size to sample down to.
                int downSampleWidth  = 1024 / 2;
                int downSampleHeight = 1024 / 2;

                // Create the down sample render to texture object.
                DownSampleTexure = new DRenderTexture();

                // Initialize the down sample render to texture object.
                if (!DownSampleTexure.Initialize(D3D.Device, downSampleWidth, downSampleHeight, DSystemConfiguration.ScreenDepth, DSystemConfiguration.ScreenNear))
                {
                    return(false);
                }

                // Create the small ortho window object.
                SmallWindow = new DOrthoWindow();

                // Initialize the small ortho window object.
                if (!SmallWindow.Initialize(D3D.Device, downSampleWidth, downSampleHeight))
                {
                    return(false);
                }

                // Create the texture shader object.
                TextureShader = new DTextureShader();

                // Initialize the texture shader object.
                if (!TextureShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the horizontal blur render to texture object.
                HorizontalBlurTexture = new DRenderTexture();

                // Initialize the horizontal blur render to texture object.
                if (!HorizontalBlurTexture.Initialize(D3D.Device, downSampleWidth, downSampleHeight, DSystemConfiguration.ScreenDepth, 0.1f))
                {
                    return(false);
                }

                // Create the horizontal blur shader object.
                HorizontalBlurShader = new DHorizontalBlurShader();

                // Initialize the horizontal blur shader object.
                if (!HorizontalBlurShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the vertical blur render to texture object.
                VerticalBlurTexture = new DRenderTexture();

                // Initialize the vertical blur render to texture object.
                if (!VerticalBlurTexture.Initialize(D3D.Device, downSampleWidth, downSampleHeight, DSystemConfiguration.ScreenDepth, 0.1f))
                {
                    return(false);
                }

                // Create the vertical blur shader object.
                VerticalBlurShader = new DVerticalBlurShader();

                // Initialize the vertical blur shader object.
                if (!VerticalBlurShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the up sample render to texture object.
                UpSampleTexure = new DRenderTexture();

                // Initialize the up sample render to texture object.
                if (!UpSampleTexure.Initialize(D3D.Device, 1024, 1024, DSystemConfiguration.ScreenDepth, 0.1f))
                {
                    return(false);
                }

                // Create the full screen ortho window object.
                FullScreenWindow = new DOrthoWindow();

                // Initialize the full screen ortho window object.
                if (!FullScreenWindow.Initialize(D3D.Device, 1024, 1024))
                {
                    return(false);
                }

                // Create the soft shadow shader object.
                SoftShadowShader = new DSoftShadowShader();

                // Initialize the soft shadow shader object.
                if (!SoftShadowShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle, string appTitle, int testTimeSeconds)
        {
            try
            {
                // Create the input object.
                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 timer object.
                Timer = new DTimer();

                // Initialize the timer object.
                if (!Timer.Initialize())
                {
                    return(false);
                }

                // Create the position object.
                Position = new DPosition();

                // Set the initial position.
                Position.SetPosition(0.0f, 7.0f, -11.0f);
                Position.SetRotation(20.0f, 0.0f, 0.0f);
                #endregion

                #region Initialize Camera
                // Create the camera object
                Camera = new DCamera();

                // Create the light object.
                Light = new DLight();

                // Initialize the light object.
                Light.GenerateOrthoMatrix(15.0f, 15.0f, SHADOWMAP_DEPTH, SHADOWMAP_NEAR);
                #endregion

                // Create the ground model object.
                GroundModel = new DModel();

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "dirt.bmp", 2.0f))
                {
                    return(false);
                }

                // Set the position for the ground model.
                GroundModel.SetPosition(0.0f, 1.0f, 0.0f);

                // Create the tree object.
                TreeModel = new DTreeModel();

                // Initialize the shadow shader object.
                if (!TreeModel.Initialize(D3D.Device, "trunk001.txt", "trunk001.bmp", "leaf001.txt", "leaf001.bmp", 0.1f))
                {
                    return(false);
                }

                // Set the position for the tree model.
                TreeModel.SetPosition(0.0f, 1.0f, 0.0f);

                // Create the render to texture object.
                RenderTexture = new DRenderTexture();

                // Initialize the render to texture object.
                if (!RenderTexture.Initialize(D3D.Device, SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT, SHADOWMAP_DEPTH, SHADOWMAP_NEAR))
                {
                    return(false);
                }

                // Create the depth shader object.
                DepthShader = new DDepthShader();

                // Initialize the depth shader object.
                if (!DepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the transparent depth shader object.
                TransparentDepthShader = new DTransparentDepthShader();

                // Initialize the transparent depth shader object.
                if (!TransparentDepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the shadow shader object.
                ShadowShader = new DShadowShader();

                // Initialize the shadow shader object.
                if (!ShadowShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                DPerfLogger.Initialize("WinForms C# SharpDX: " + configuration.Width + "x" + configuration.Height + " VSync:" + DSystemConfiguration.VerticalSyncEnabled + " FullScreen:" + DSystemConfiguration.FullScreen + "   " + appTitle, testTimeSeconds, configuration.Width, configuration.Height);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }