Esempio n. 1
0
        private bool RenderScene()
        {
            // Generate the view matrix based on the camera position.
            Camera.Render();

            // Get the world, view, and projection matrices from camera and d3d objects.
            var viewMatrix       = Camera.ViewMatrix;
            var worldMatrix      = D3D.WorldMatrix;
            var projectionMatrix = D3D.ProjectionMatrix;

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First()))
            {
                return(false);
            }

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Translate to the right by one unit and towards the camera by one unit.
            Matrix.Translation(1, 0, -1, out worldMatrix);

            // Setup a clipping plane.
            var blendAmount = 0.5f;

            // Turn on alpha blending for the transparency to work.
            D3D.TurnOnAlphaBlending();

            // Put the second square model on the graphics pipeline.
            Model2.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!TransparentShader.Render(D3D.DeviceContext, Model2.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model2.TextureCollection.Select(item => item.TextureResource).ToArray(), blendAmount))
            {
                return(false);
            }

            // Turn off alpha blending.
            D3D.TurnOffAlphaBlending();

            return(true);
        }
Esempio n. 2
0
        public void Shutdown()
        {
            // Release the camera object.
            Camera = null;

            // Release the transparent shader object.
            TransparentShader?.ShutDown();
            TransparentShader = null;
            // Release the texture shader object.
            TextureShader?.ShutDown();
            TextureShader = null;
            //// Release the model object.
            Model?.Shutdown();
            Model = null;
            Model2?.Shutdown();
            Model2 = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
Esempio n. 3
0
        public void Shutdown()
        {
            // Release the reflection shader object.
            if (ReflectionShader != null)
            {
                ReflectionShader.Shuddown();
                ReflectionShader = null;
            }

            // Release the transparent shader object.
            if (TransparentShader != null)
            {
                TransparentShader.Shuddown();
                TransparentShader = null;
            }

            // Release the translate shader object.
            if (TranslateShader != null)
            {
                TranslateShader.Shuddown();
                TranslateShader = null;
            }

            // Release the clip plane shader object.
            if (ClipPlaneShader != null)
            {
                ClipPlaneShader.Shuddown();
                ClipPlaneShader = null;
            }

            // Release the fog shader object.
            if (FogShader != null)
            {
                FogShader.Shuddown();
                FogShader = null;
            }

            // Release the texture shader object.
            if (TextureShader != null)
            {
                TextureShader.Shuddown();
                TextureShader = null;
            }

            // Release the debug window object.
            if (DebugWindow != null)
            {
                DebugWindow.Shutdown();
                DebugWindow = null;
            }

            // Release the debug render to texture object.
            if (RenderDebugTexture != null)
            {
                RenderDebugTexture.Shutdown();
                RenderDebugTexture = null;
            }

            // Release the render to texture object.
            if (RenderReflectionTexture != null)
            {
                RenderReflectionTexture.Shutdown();
                RenderReflectionTexture = null;
            }

            // Release the light object.
            Light = null;

            // Release the shader object.
            if (LightShader != null)
            {
                LightShader.Shuddown();
                LightShader = null;
            }

            // Release the model object.
            if (Model != null)
            {
                Model.Shutdown();
                Model = null;
            }

            // Release the light shader object.
            if (BumpMapShader != null)
            {
                BumpMapShader.Shuddown();
                BumpMapShader = null;
            }

            // Release the model object.
            if (BumpMapModel != null)
            {
                BumpMapModel.Shutdown();
                BumpMapModel = null;
            }

            // Release the text object.
            if (Text != null)
            {
                Text.Shutdown();
                Text = null;
            }

            // Release the camera object.
            if (Camera != null)
            {
                Camera = null;
            }

            // Release the Direct3D object.
            if (D3D != null)
            {
                D3D.Shutdown();
                D3D = null;
            }
        }
Esempio n. 4
0
        public bool Initialize(SystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                #region Initialize System
                // Create the Direct3D object.
                D3D = new DX11();
                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    MessageBox.Show("Could not initialize Direct3D", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

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

                #region Initialize Models
                // Create the model class.
                Model = new Model();

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, "square.txt", new[] { "dirt01.dds" }))
                {
                    MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the model class.
                Model2 = new Model();

                // Initialize the model object.
                if (!Model2.Initialize(D3D.Device, "square.txt", new[] { "stone01.dds" }))
                {
                    MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                #region Debug Model
                if (SystemConfiguration.DebugWindowOn)
                {
                    // Create the render to texture object.
                    RenderTexture = new RenderTexture();

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

                    // Create the debug window object.
                    DebugWindow = new DebugWindow();

                    // Initialize the debug window object.
                    if (!DebugWindow.Initialize(D3D.Device, configuration.Width, configuration.Height, 100, 100 * configuration.Height / configuration.Width))
                    {
                        MessageBox.Show("Could not initialize the debug window object.", "Error", MessageBoxButtons.OK);
                        return(false);
                    }

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

                    // Initialize the texture shader object.
                    if (!TextureShader.Initialize(D3D.Device, windowHandle))
                    {
                        MessageBox.Show("Could not initialize the texture shader object.", "Error", MessageBoxButtons.OK);
                        return(false);
                    }
                }
                #endregion
                #endregion

                #region Initialize Textures
                // Create the shader object.
                TextureShader = new TextureShader();

                // Initialize the shader object.
                if (!TextureShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the shader", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the shader object.
                TransparentShader = new TransparentShader();

                // Initialize the shader object.
                if (!TransparentShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the shader", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                #region Initialize Data
                // Create the light object.
                Light = new Light();

                // Initialize the light object.
                Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
                Light.SetDiffuseColor(1, 1, 1, 1f);
                Light.SetDirection(0, 0, 1);
                Light.SetSpecularColor(0, 1, 1, 1);
                Light.SetSpecularPower(16);
                #endregion

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