Пример #1
0
        // Methods
        public bool Initialize(SharpDX.Direct3D11.Device device, DSystemConfiguration configuration, int bitmapWidth, int bitmapHeight, string textureFileName)
        {
            // Store the screen size.
            ScreenWidth  = configuration.Width;
            ScreenHeight = configuration.Height;

            // Store the size in pixels that this bitmap should be rendered at.
            BitmapWidth  = bitmapWidth;
            BitmapHeight = bitmapHeight;

            // Initialize the previous rendering position to negative one.
            PreviousPosX = -1;
            PreviousPosY = -1;

            // Initialize the vertex and index buffer that hold the geometry for the bitmap quad.
            if (!InitializeBuffers(device))
            {
                return(false);
            }

            // Load the texture for this bitmap.
            if (!LoadTexture(device, textureFileName))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        public bool Initialze(DDX11 D3D, IntPtr windowHandle, DSystemConfiguration configuration)
        {
            // Create the user interface object.
            UserInterface = new DUserInterface();
            // Initialize the user interface object.
            if (!UserInterface.Initialize(D3D, configuration))
            {
                return(false);
            }

            // Create the camera object
            Camera = new DCamera();
            // Initialize a base view matrix with the camera for 2D user interface rendering.
            Camera.SetPosition(0.0f, 0.0f, -10.0f);
            Camera.Render();
            Camera.RenderBaseViewMatrix();

            // Create the position object.
            Position = new DPosition();
            // Set the initial position and rotation of the viewer.28.0f, 5.0f, -10.0f
            Position.SetPosition(512.0f, 30.0f, 1034.0f);
            Position.SetRotation(0.0f, 180.0f, 0.0f);

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

            // Initialize the light object.
            Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
            Light.Direction = new Vector3(-0.5f, -1.0f, -0.5f);

            // Create and initialize the frustum object.
            Frustum = new DFrustum();
            Frustum.Initialize(DSystemConfiguration.ScreenDepth);

            // Create the sky dome object.
            SkyDomeModel = new DSkyDome();

            // Initialize the sky dome object.
            if (!SkyDomeModel.Initialize(D3D.Device, "skydome.txt"))
            {
                return(false);
            }

            // Initialize the terrain object.
            Terrain = new DTerrain();
            // Initialize the ground model object.
            if (!Terrain.Initialize(D3D.Device, "setupS2TutTerr08.txt"))
            {
                return(false);
            }

            // Set the UI to display by default.
            DisplayUI = true;
            // Set wire frame rendering initially to enabled.
            WireFrame = false;
            // Set the rendering of cell lines initially to enabled.
            CellLines = true;

            return(true);
        }
Пример #3
0
        public bool Initialize(DSystemConfiguration consifguration, IntPtr windowsHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(consifguration, windowsHandle))
                {
                    return(false);
                }

                // Create the Timer
                Timer = new DTimer();

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

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
        // Methods.
        internal bool Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
        {
            // Screen the screen size which will be used for positioning the mouse cursor.
            _ScreenWidth  = configuration.Width;
            _ScreenHeight = configuration.Height;

            // Initialize the location of the mouse on the screen.
            _MouseX = 0;
            _MouseY = 0;

            // Initialize the main direct input interface.
            _DirectInput = new DirectInput();

            #region Keyboard related Initiailization
            // Initialize the direct interface for the keyboard.
            _Keyboard = new Keyboard(_DirectInput);
            _Keyboard.Properties.BufferSize = 256;

            // Set the cooperative level of the keyboard to not share with other programs.
            // use 'CooperativeLevel.Background' for debugging purpose on Both the Mouse and Keyboard as well as NonExclusive on the keybaord.
            _Keyboard.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            try
            {
                _Keyboard.Acquire();
            }
            catch (SharpDXException sEx)
            {
                if (sEx.ResultCode.Failure)
                {
                    return(false);
                }
            }
            #endregion

            #region Mouse related Initiailization
            // Initialize the direct interface for the mouse.
            _Mouse = new Mouse(_DirectInput);
            _Mouse.Properties.AxisMode = DeviceAxisMode.Relative;

            // Set the cooperative level of the mouse to share with other programs.
            _Mouse.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);

            try
            {
                _Mouse.Acquire();
            }
            catch (SharpDXException sEx)
            {
                if (sEx.ResultCode.Failure)
                {
                    return(false);
                }
            }
            #endregion

            return(true);
        }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

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

                // Initialize a base view matrix the camera for 2D user interface rendering.
                Camera.SetPosition(0, 0, -5);
                Camera.Render();

                // Create the model class.
                BumpMapModel = new DBumpMapModel();

                // Initialize the model object.
                if (!BumpMapModel.Initialize(D3D.Device, "Cube.txt", new[] { "stone02.bmp", "bump02.bmp", "spec02.bmp" }))
                {
                    MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the bump map shader object.
                SpecMapShader = new DSpecMapShader();

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

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

                // Initialize the light object.
                Light.SetDiffuseColor(1, 1, 1, 1f);
                Light.SetDirection(0, 0, 1);
                Light.SetSpecularColor(0, 1, 1, 1);
                Light.SetSpecularPower(16);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
        // Methods
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowsHandle))
                {
                    return(false);
                }

                // Create the Timer
                Timer = new DTimer();

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

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

                // Set the initial position of the camera.
                Camera.SetPosition(0, 0, -10);

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

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, DSystemConfiguration.DataFilePath + "seafloor.bmp"))
                {
                    MessageBox.Show("Could not initialize the model object.");
                    return(false);
                }

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

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

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        // Methods
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowsHandle))
                {
                    return(false);
                }

                // Create the Timer
                Timer = new DTimer();

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

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

                // Set the initial position of the camera.  moved closer inTutorial 7
                Camera.SetPosition(0, 0, -10);

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

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

                // Create the bitmap object.
                Bitmap = new DBitmap();

                // Initialize the bitmap object.
                if (!Bitmap.Initialize(D3D.Device, configuration.Width, configuration.Height, "seafloor.bmp", 256, 256))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #8
0
        public bool Initialize(DSystemConfiguration consifguration, IntPtr windowsHandle)
        {
            bool result = false;

            D3D    = new DDX11();
            result = D3D.Initialize(consifguration, windowsHandle);
            Timer  = new DTimer();
            result = Timer.Initialize();

            return(result);
        }
Пример #9
0
        // Mathods
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // I nitialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

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

                // Set the initial position of the camera.
                Camera.SetPosition(0, 0, -10);

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

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device))
                {
                    return(false);
                }

                // Create the color shader object.
                ColorShader = new DColorShader();

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

                // Create the Timer
                Timer = new DTimer();

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

                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)
        {
            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 position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -5.0f);
                #endregion

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

                //// Initialize the ground model object.
                if (!Model.Initialize(D3D.Device, "square.txt", new[] { "fire01.bmp", "noise01.bmp", "alpha02.bmp" }))
                {
                    MessageBox.Show("Could not initialize the ground model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                #region Initialize Shaders
                // Create the fire shader object.
                FireShader = new DFireShader();

                if (!FireShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
        // Puvlix Methods
        public bool Initialize(SharpDX.Direct3D11.Device device, DSystemConfiguration configuration)
        {
            try
            {
                // Initialize and set up the render target description.
                Texture2DDescription textureDesc = new Texture2DDescription()
                {
                    Width             = configuration.Width,
                    Height            = configuration.Height,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.R32G32B32A32_Float,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default,
                    BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    OptionFlags       = ResourceOptionFlags.None
                };

                // Create the render target texture.
                RenderTargetTexture = new Texture2D(device, textureDesc);

                // Initialize and setup the render target view
                RenderTargetViewDescription renderTargetViewDesc = new RenderTargetViewDescription()
                {
                    Format    = textureDesc.Format,
                    Dimension = RenderTargetViewDimension.Texture2D
                };
                renderTargetViewDesc.Texture2D.MipSlice = 0;

                // Create the render target view.
                RenderTargetView = new RenderTargetView(device, RenderTargetTexture, renderTargetViewDesc);

                // Initialize and setup the shader resource view
                ShaderResourceViewDescription shaderResourceViewDesc = new ShaderResourceViewDescription()
                {
                    Format    = textureDesc.Format,
                    Dimension = ShaderResourceViewDimension.Texture2D,
                };
                shaderResourceViewDesc.Texture2D.MipLevels       = 1;
                shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;

                // Create the render target view.
                ShaderResourceView = new ShaderResourceView(device, RenderTargetTexture, shaderResourceViewDesc);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #12
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, 2.0f, -10.0f);
                #endregion

                #region Initialize Models
                // Create the Flat Plane  model class.
                FloorModel = new DModel();

                // Create the floor model object.
                if (!FloorModel.Initialize(D3D.Device, "floor.txt"))
                {
                    MessageBox.Show("Could not initialize the ground model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

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

                if (!DepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #13
0
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

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

                // Initialize a base view matrix the camera for 2D user interface rendering.
                Camera.SetPosition(0, 0, -1);
                Camera.Render();

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

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

                // Create the shader object.
                FogShader = new DFogShader();

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

                Camera.SetPosition(0, 0, -5.0f);

                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)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

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

                // Initialize a base view matrix the camera for 2D user interface rendering.
                Camera.SetPosition(0, 0, -1);
                Camera.Render();
                var baseViewMatrix = Camera.ViewMatrix;

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

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

                // Create the multitexture shader object.
                MultiTextureLightShader = new DMultiTextureLightShader();

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

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #15
0
 internal void Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
 {
     DirectInput = new DirectInput();
     Keyboard    = new Keyboard(DirectInput);
     Keyboard.Properties.BufferSize = 256;
     Keyboard.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);
     try
     {
         Keyboard.Acquire();
     }
     catch (SharpDXException ex)
     {
         throw ex;
     }
 }
Пример #16
0
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

                // Create the Timer
                Timer = new DTimer();

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

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

                // Initialize a base view matrix the camera for 2D user interface rendering.
                Camera.SetPosition(0, 0, -1);
                Camera.Render();
                var baseViewMatrix = Camera.ViewMatrix;

                // Create the text object.
                Text = new DTextClass();

                if (!Text.Initialize(D3D.Device, D3D.DeviceContext, windowHandle, configuration.Width, configuration.Height, baseViewMatrix))
                {
                    return(false);
                }

                Camera.SetPosition(0, 0, -10.0f);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #17
0
        public bool Initialize(DSystemConfiguration consifguration, IntPtr windowsHandle)
        {
            bool result = false;

            D3D    = new DDX11();
            result = D3D.Initialize(consifguration, windowsHandle);
            Timer  = new DTimer();
            result = Timer.Initialize();
            Camera = new DCamera();
            Camera.SetPosition(0, 0, -10);
            Model         = new DModel();
            result        = Model.Initialize(D3D.Device, DSystemConfiguration.DataFilePath + "stone01.bmp");
            TextureShader = new DTextureShader();
            result        = TextureShader.Initialize(D3D.Device, windowsHandle);
            return(result);
        }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

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

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

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

                // Create the shader object.
                TranslateShader = new DTranslateShader();

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

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

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #19
0
        // Methods
        public bool Initialize(SharpDX.Direct3D11.Device device, DFont font, DSystemConfiguration configuration, int maxLength, string text, int positionX, int positionY, float red, float green, float blue, bool shadowed, SharpDX.Direct3D11.DeviceContext deviceContext)
        {
            // Store the screen width and height.
            ScreenWidth  = configuration.Width;
            ScreenHeight = configuration.Height;

            // Store the maximum length of the sentence.
            MaxLength = maxLength;

            // Initalize the sentence.
            if (!InitializeSentence(device, font, text, positionX, positionY, red, green, blue, deviceContext))
            {
                return(false);
            }

            return(true);
        }
        public bool Initialize(DSystemConfiguration consifguration, IntPtr windowsHandle)
        {
            bool result = false;

            D3D    = new DDX11();
            result = D3D.Initialize(consifguration, windowsHandle);
            Camera = new DCamera();
            Camera.SetPosition(0, 0, -10);
            Model       = new DModel();
            result      = Model.Initialize(D3D.Device);
            ColorShader = new DColorShader();
            result      = ColorShader.Initialize(D3D.Device, windowsHandle);
            Timer       = new DTimer();
            result      = Timer.Initialize();

            return(result);
        }
        // Methods
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowsHandle))
                {
                    return(false);
                }

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

                // Set the initial position of the camera.
                Camera.SetPosition(0.0f, -1.6f, -5.0f);

                // Create the particle shader object.
                ParticleShader = new DParticleShader();

                // Initialize the particle shader object.
                if (!ParticleShader.Initialize(D3D.Device, windowsHandle))
                {
                    return(false);
                }

                // Create the particle system object.
                ParticleSystem = new DParticleSystem();

                // Initialize the particle system object.
                if (!ParticleSystem.Initialize(D3D.Device, "star.bmp"))
                {
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #22
0
        public bool Initialze(DDX11 D3D, IntPtr windowHandle, DSystemConfiguration configuration)
        {
            // Create the user interface object.
            UserInterface = new DUserInterface();
            // Initialize the user interface object.
            if (!UserInterface.Initialize(D3D, configuration))
            {
                return(false);
            }

            // Create the camera object
            Camera = new DCamera();
            // Initialize a base view matrix with the camera for 2D user interface rendering.
            Camera.SetPosition(0.0f, 0.0f, -10.0f);
            Camera.Render();
            Camera.RenderBaseViewMatrix();

            // Create the position object.
            Position = new DPosition();
            // Set the initial position and rotation of the viewer.28.0f, 5.0f, -10.0f
            Position.SetPosition(128.0f, 10.0f, -10.0f);
            Position.SetRotation(0.0f, 0.0f, 0.0f);

            // Initialize the terrain object.
            Terrain = new DTerrain();
            // Initialize the ground model object.
            if (!Terrain.Initialize(D3D.Device, "setup.txt"))
            {
                return(false);
            }

            // Set the UI to display by default.
            DisplayUI = true;

            // Set wire frame rendering initially to enabled.
            WireFrame = true;

            return(true);
        }
        // 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);
            }
        }
        // Methods
        public bool Initialize(DDX11 D3Ddevice, DSystemConfiguration configuration)
        {
            // Create the first font object.
            Font1 = new DFont();

            // Initialize the first font object.
            if (!Font1.Initialize(D3Ddevice.Device, "font01.txt", "font01.bmp", 32.0f, 3))
            {
                return(false);
            }

            // Create the text object for the fps string.
            FpsString = new DText();

            // Initialize the fps text string.
            if (!FpsString.Initialize(D3Ddevice.Device, Font1, configuration, 16, "FPS: 0", 10, 50, 0.0f, 1.0f, 0.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }

            // Initial the previous frame fps.
            PreviousFPS = -1;

            // Create the text objects for the position strings.
            PositionStrings = new DText[6];
            for (int i = 0; i < PositionStrings.Length; i++)
            {
                PositionStrings[i] = new DText();
            }

            // Initialize the position text strings.
            if (!PositionStrings[0].Initialize(D3Ddevice.Device, Font1, configuration, 16, "X: 0", 10, 90, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }
            if (!PositionStrings[1].Initialize(D3Ddevice.Device, Font1, configuration, 16, "Y: 0", 10, 110, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }
            if (!PositionStrings[2].Initialize(D3Ddevice.Device, Font1, configuration, 16, "Z: 0", 10, 130, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }
            if (!PositionStrings[3].Initialize(D3Ddevice.Device, Font1, configuration, 16, "rX: 0", 10, 170, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }
            if (!PositionStrings[4].Initialize(D3Ddevice.Device, Font1, configuration, 16, "rY: 0", 10, 190, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }
            if (!PositionStrings[5].Initialize(D3Ddevice.Device, Font1, configuration, 16, "rZ: 0", 10, 210, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }

            // Initialize the previous frame position.
            PreviousPositions = new int[6];
            VideoStrings      = new DText[2];
            for (int i = 0; i < VideoStrings.Length; i++)
            {
                VideoStrings[i] = new DText();
            }

            // Initialize the position text strings.
            if (!VideoStrings[0].Initialize(D3Ddevice.Device, Font1, configuration, 256, D3Ddevice.VideoCardDescription, 10, 10, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }
            if (!VideoStrings[1].Initialize(D3Ddevice.Device, Font1, configuration, 64, D3Ddevice.VideoCardMemory.ToString(), 10, 30, 1.0f, 1.0f, 1.0f, false, D3Ddevice.DeviceContext))
            {
                return(false);
            }

            return(true);
        }
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                #region Environment Configuration
                // Store the vsync setting.
                VerticalSyncEnabled = DSystemConfiguration.VerticalSyncEnabled;

                // Create a DirectX graphics interface factory.
                var factory = new Factory1();

                // Use the factory to create an adapter for the primary graphics interface (video card).
                var adapter = factory.GetAdapter1(0);

                // Get the primary adapter output (monitor).
                var monitor = adapter.GetOutput(0);

                // Get modes that fit the DXGI_FORMAT_R8G8B8A8_UNORM display format for the adapter output (monitor).
                var modes = monitor.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced);

                // Now go through all the display modes and find the one that matches the screen width and height.
                // When a match is found store the the refresh rate for that monitor, if vertical sync is enabled.
                // Otherwise we use maximum refresh rate.
                var rational = new Rational(0, 1);
                if (VerticalSyncEnabled)
                {
                    foreach (var mode in modes)
                    {
                        if (mode.Width == configuration.Width && mode.Height == configuration.Height)
                        {
                            rational = new Rational(mode.RefreshRate.Numerator, mode.RefreshRate.Denominator);
                            break;
                        }
                    }
                }

                // Get the adapter (video card) description.
                var adapterDescription = adapter.Description;

                // Store the dedicated video card memory in megabytes.
                VideoCardMemory = adapterDescription.DedicatedVideoMemory >> 10 >> 10;

                // Convert the name of the video card to a character array and store it.
                VideoCardDescription = adapterDescription.Description.Trim('\0');

                // Release the adapter output.
                monitor.Dispose();
                // Release the adapter.
                adapter.Dispose();
                // Release the factory.
                factory.Dispose();
                #endregion

                #region Initialize swap chain and d3d device
                // Initialize the swap chain description.
                var swapChainDesc = new SwapChainDescription()
                {
                    // Set to a single back buffer.
                    BufferCount = 1,
                    // Set the width and height of the back buffer.
                    ModeDescription = new ModeDescription(configuration.Width, configuration.Height, rational, Format.R8G8B8A8_UNorm)
                    {
                        Scaling = DisplayModeScaling.Unspecified, ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
                    },
                    // Set the usage of the back buffer.
                    Usage = Usage.RenderTargetOutput,
                    // Set the handle for the window to render to.
                    OutputHandle = windowHandle,
                    // Turn multisampling off.
                    SampleDescription = new SampleDescription(1, 0),
                    // Set to full screen or windowed mode.
                    IsWindowed = !DSystemConfiguration.FullScreen,
                    // Don't set the advanced flags.
                    Flags = SwapChainFlags.None,
                    // Discard the back buffer content after presenting.
                    SwapEffect = SwapEffect.Discard
                };

                // Create the swap chain, Direct3D device, and Direct3D device context.
                SharpDX.Direct3D11.Device device;
                SwapChain swapChain;
                SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);

                Device        = device;
                SwapChain     = swapChain;
                DeviceContext = device.ImmediateContext;
                #endregion

                #region Initialize buffers
                // Get the pointer to the back buffer.
                var backBuffer = Texture2D.FromSwapChain <Texture2D>(SwapChain, 0);

                // Create the render target view with the back buffer pointer.
                RenderTargetView = new RenderTargetView(device, backBuffer);

                // Release pointer to the back buffer as we no longer need it.
                backBuffer.Dispose();

                // Initialize and set up the description of the depth buffer.
                var depthBufferDesc = new Texture2DDescription()
                {
                    Width             = configuration.Width,
                    Height            = configuration.Height,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.D24_UNorm_S8_UInt,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default,
                    BindFlags         = BindFlags.DepthStencil,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    OptionFlags       = ResourceOptionFlags.None
                };

                // Create the texture for the depth buffer using the filled out description.
                DepthStencilBuffer = new Texture2D(device, depthBufferDesc);
                #endregion

                #region Initialize Depth Enabled Stencil
                // Initialize and set up the description of the stencil state.
                var depthStencilDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = true,
                    DepthWriteMask   = DepthWriteMask.All,
                    DepthComparison  = Comparison.Less,
                    IsStencilEnabled = true,
                    StencilReadMask  = 0xFF,
                    StencilWriteMask = 0xFF,
                    // Stencil operation if pixel front-facing.
                    FrontFace = new DepthStencilOperationDescription()
                    {
                        FailOperation      = StencilOperation.Keep,
                        DepthFailOperation = StencilOperation.Increment,
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Always
                    },
                    // Stencil operation if pixel is back-facing.
                    BackFace = new DepthStencilOperationDescription()
                    {
                        FailOperation      = StencilOperation.Keep,
                        DepthFailOperation = StencilOperation.Decrement,
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Always
                    }
                };

                // Create the depth stencil state.
                DepthStencilState = new DepthStencilState(Device, depthStencilDesc);
                #endregion

                #region Initialize Output Merger
                // Set the depth stencil state.
                DeviceContext.OutputMerger.SetDepthStencilState(DepthStencilState, 1);

                // Initialize and set up the depth stencil view.
                var depthStencilViewDesc = new DepthStencilViewDescription()
                {
                    Format    = Format.D24_UNorm_S8_UInt,
                    Dimension = DepthStencilViewDimension.Texture2D,
                    Texture2D = new DepthStencilViewDescription.Texture2DResource()
                    {
                        MipSlice = 0
                    }
                };

                // Create the depth stencil view.
                DepthStencilView = new DepthStencilView(Device, DepthStencilBuffer, depthStencilViewDesc);

                // Bind the render target view and depth stencil buffer to the output render pipeline.
                DeviceContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView);
                #endregion

                #region Initialize Raster State
                // Setup the raster description which will determine how and what polygon will be drawn.
                var rasterDesc = new RasterizerStateDescription()
                {
                    IsAntialiasedLineEnabled = false,
                    #region Tut 24 EX 2: for Clip Planning wqith raised camera nd culling off.
                    // CullMode = CullMode.None,
                    #endregion
                    CullMode                = CullMode.Back,
                    DepthBias               = 0,
                    DepthBiasClamp          = .0f,
                    IsDepthClipEnabled      = true,
                    FillMode                = FillMode.Solid,
                    IsFrontCounterClockwise = false,
                    IsMultisampleEnabled    = false,
                    IsScissorEnabled        = false,
                    SlopeScaledDepthBias    = .0f
                };

                // Create the rasterizer state from the description we just filled out.
                RasterState = new RasterizerState(Device, rasterDesc);
                #endregion

                #region Initialize Rasterizer
                // Now set the rasterizer state.
                DeviceContext.Rasterizer.State = RasterState;

                ViewPort = new ViewportF(0.0f, 0.0f, (float)configuration.Width, (float)configuration.Height, 0.0f, 1.0f);

                // Setup and create the viewport for rendering.
                DeviceContext.Rasterizer.SetViewport(ViewPort);
                #endregion

                #region Initialize matrices
                // Initialize the world matrix to the identity matrix.
                WorldMatrix = Matrix.Identity;

                // Create an orthographic projection matrix for 2D rendering.
                OrthoMatrix = Matrix.OrthoLH(configuration.Width, configuration.Height, DSystemConfiguration.ScreenNear, DSystemConfiguration.ScreenDepth);
                #endregion

                #region Initialize Depth Disabled Stencil
                // Now create a second depth stencil state which turns off the Z buffer for 2D rendering. Added in Tutorial 11
                // The difference is that DepthEnable is set to false.
                // All other parameters are the same as the other depth stencil state.
                var depthDisabledStencilDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = false,
                    DepthWriteMask   = DepthWriteMask.All,
                    DepthComparison  = Comparison.Less,
                    IsStencilEnabled = true,
                    StencilReadMask  = 0xFF,
                    StencilWriteMask = 0xFF,
                    // Stencil operation if pixel front-facing.
                    FrontFace = new DepthStencilOperationDescription()
                    {
                        FailOperation      = StencilOperation.Keep,
                        DepthFailOperation = StencilOperation.Increment,
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Always
                    },
                    // Stencil operation if pixel is back-facing.
                    BackFace = new DepthStencilOperationDescription()
                    {
                        FailOperation      = StencilOperation.Keep,
                        DepthFailOperation = StencilOperation.Decrement,
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Always
                    }
                };

                // Create the depth stencil state.
                DepthDisabledStencilState = new DepthStencilState(Device, depthDisabledStencilDesc);
                #endregion

                #region Initialize Blend States
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        // 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 and rotation of the camera.
                Camera.SetPosition(0.0f, 7.0f, -10.0f);
                Camera.SetRotation(35.0f, 0.0f, 0.0f);
                #endregion

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

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

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

                // Initialize the cube model object.
                if (!CubeModel.Initialize(D3D.Device, "cube.txt", "seafloor.bmp"))
                {
                    return(false);
                }
                #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.Position = new Vector3(2.0f, 5.0f, -2.0f);
                #endregion

                #region Initialize Shaders
                // Create the projection shader object.
                ProjectionShader = new DProjectionShader();

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

                // Create the projection texture object.
                ProjectionTexture = new DTexture();

                // Initialize the projection texture object.
                if (!ProjectionTexture.Initialize(D3D.Device, DSystemConfiguration.DataFilePath + "grate.bmp"))
                {
                    return(false);
                }

                // Create the view point object.
                ViewPoint = new DViewPoint();

                // Initialize the view point object.
                ViewPoint.SetPosition(2.0f, 5.0f, -2.0f);
                ViewPoint.SetLookAt(0.0f, 0.0f, 0.0f);
                ViewPoint.SetProjectionParameters((float)(Math.PI / 2.0f), 1.0f, 0.1f, 100.0f);
                ViewPoint.GenerateViewMatrix();
                ViewPoint.GenerateProjectionMatrix();
                #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 windowsHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowsHandle))
                {
                    return(false);
                }

                // Create the Timer
                Timer = new DTimer();

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

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

                // Set the initial position of the camera.  moved closer inTutorial 7
                Camera.SetPosition(0, 0, -10.0f);

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

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, "Cube.txt", "seafloor.bmp"))
                {
                    MessageBox.Show("Could not initialize the model object.");
                    return(false);
                }

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

                // Initialize the texture shader object.
                if (!LightShader.Initialize(D3D.Device, windowsHandle))
                {
                    MessageBox.Show("Could not initialize the texture shader object.");
                    return(false);
                }

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

                // Iniialize the light object.  Changed to white in Tutorial 7
                Light.SetDiffuseColour(1, 1, 1, 1);
                Light.SetDirection(0, 0, 1);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #28
0
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                VerticalSyncEnabled = DSystemConfiguration.VerticalSyncEnabled;
                var factory  = new Factory1();
                var adapter  = factory.GetAdapter1(0);
                var monitor  = adapter.GetOutput(0);
                var modes    = monitor.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced);
                var rational = new Rational(0, 1);
                if (VerticalSyncEnabled)
                {
                    foreach (var mode in modes)
                    {
                        if (mode.Width == configuration.Width && mode.Height == configuration.Height)
                        {
                            rational = new Rational(mode.RefreshRate.Numerator, mode.RefreshRate.Denominator);
                            break;
                        }
                    }
                }
                var adapterDescription = adapter.Description;
                VideoCardMemory      = adapterDescription.DedicatedVideoMemory >> 10 >> 10;
                VideoCardDescription = adapterDescription.Description;
                monitor.Dispose();
                adapter.Dispose();
                factory.Dispose();

                var swapChainDesc = new SwapChainDescription()
                {
                    BufferCount       = 1,
                    ModeDescription   = new ModeDescription(configuration.Width, configuration.Height, rational, Format.R8G8B8A8_UNorm),
                    Usage             = Usage.RenderTargetOutput,
                    OutputHandle      = windowHandle,
                    SampleDescription = new SampleDescription(1, 0),
                    IsWindowed        = !DSystemConfiguration.FullScreen,
                    Flags             = SwapChainFlags.None,
                    SwapEffect        = SwapEffect.Discard
                };

                SharpDX.Direct3D11.Device device;
                SwapChain swapChain;
                SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);
                Device        = device;
                SwapChain     = swapChain;
                DeviceContext = device.ImmediateContext;

                var backBuffer = Texture2D.FromSwapChain <Texture2D>(SwapChain, 0);
                RenderTargetView = new RenderTargetView(device, backBuffer);
                backBuffer.Dispose();

                Texture2DDescription depthBufferDesc = new Texture2DDescription()
                {
                    Width             = configuration.Width,
                    Height            = configuration.Height,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.D24_UNorm_S8_UInt,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default,
                    BindFlags         = BindFlags.DepthStencil,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    OptionFlags       = ResourceOptionFlags.None
                };
                DepthStencilBuffer = new Texture2D(device, depthBufferDesc);

                DepthStencilStateDescription depthStencilDesc = new DepthStencilStateDescription()
                {
                    IsDepthEnabled   = true,
                    DepthWriteMask   = DepthWriteMask.All,
                    DepthComparison  = Comparison.Less,
                    IsStencilEnabled = true,
                    StencilReadMask  = 0xFF,
                    StencilWriteMask = 0xFF,
                    FrontFace        = new DepthStencilOperationDescription()
                    {
                        FailOperation      = StencilOperation.Keep,
                        DepthFailOperation = StencilOperation.Increment,
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Always
                    },
                    BackFace = new DepthStencilOperationDescription()
                    {
                        FailOperation      = StencilOperation.Keep,
                        DepthFailOperation = StencilOperation.Decrement,
                        PassOperation      = StencilOperation.Keep,
                        Comparison         = Comparison.Always
                    }
                };
                DepthStencilState = new DepthStencilState(Device, depthStencilDesc);
                DeviceContext.OutputMerger.SetDepthStencilState(DepthStencilState, 1);

                DepthStencilViewDescription depthStencilViewDesc = new DepthStencilViewDescription()
                {
                    Format    = Format.D24_UNorm_S8_UInt,
                    Dimension = DepthStencilViewDimension.Texture2D,
                    Texture2D = new DepthStencilViewDescription.Texture2DResource()
                    {
                        MipSlice = 0
                    }
                };
                DepthStencilView = new DepthStencilView(Device, DepthStencilBuffer, depthStencilViewDesc);
                DeviceContext.OutputMerger.SetTargets(DepthStencilView, RenderTargetView);

                RasterizerStateDescription rasterDesc = new RasterizerStateDescription()
                {
                    IsAntialiasedLineEnabled = false,
                    CullMode                = CullMode.Back,
                    DepthBias               = 0,
                    DepthBiasClamp          = .0f,
                    IsDepthClipEnabled      = true,
                    FillMode                = FillMode.Solid,
                    IsFrontCounterClockwise = false,
                    IsMultisampleEnabled    = false,
                    IsScissorEnabled        = false,
                    SlopeScaledDepthBias    = .0f
                };
                RasterState = new RasterizerState(Device, rasterDesc);
                DeviceContext.Rasterizer.State = RasterState;
                DeviceContext.Rasterizer.SetViewport(0, 0, configuration.Width, configuration.Height, 0, 1);
                ProjectionMatrix = Matrix.PerspectiveFovLH((float)(Math.PI / 4), ((float)configuration.Width / (float)configuration.Height), DSystemConfiguration.ScreenNear, DSystemConfiguration.ScreenDepth);
                WorldMatrix      = Matrix.Identity;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        // Methods
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowsHandle)
        {
            try
            {
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowsHandle))
                {
                    return(false);
                }

                // Create the Timer
                Timer = new DTimer();

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

                // Create the camera object
                Camera = new DCamera();
                // Set the initial position of the camera.  moved closer inTutorial 7
                Camera.SetPosition(0, 0, -10.0f);

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

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, "Cube.txt", "seafloor.bmp"))
                {
                    MessageBox.Show("Could not initialize the model object.");
                    return(false);
                }

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

                // Initialize the texture shader object.
                if (!LightShader.Initialize(D3D.Device, windowsHandle))
                {
                    MessageBox.Show("Could not initialize the texture shader object.");
                    return(false);
                }

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

                // Iniialize the light object.  Changed to white in Tutorial 7
                // Added Setting of Ambiant Light to 15& brightness and adjust the Light direction along the X-Axis instead of the Z to see the ambient effect easier.
                Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
                Light.SetDiffuseColour(1, 1, 1, 1);
                Light.SetDirection(1, 0, 0);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
Пример #30
0
        // Puvlix Methods
        public bool Initialize(SharpDX.Direct3D11.Device device, DSystemConfiguration configuration)
        {
            try
            {
                // Initialize and set up the render target description.
                Texture2DDescription textureDesc = new Texture2DDescription()
                {
                    // Shadow Map Texture size as a 1024x1024 Square
                    Width             = 1024,
                    Height            = 1024,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.R32G32B32A32_Float,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default,
                    BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    OptionFlags       = ResourceOptionFlags.None
                };

                // Create the render target texture.
                RenderTargetTexture = new Texture2D(device, textureDesc);

                // Setup the description of the render target view.
                RenderTargetViewDescription renderTargetViewDesc = new RenderTargetViewDescription()
                {
                    Format    = textureDesc.Format,
                    Dimension = RenderTargetViewDimension.Texture2D,
                };
                renderTargetViewDesc.Texture2D.MipSlice = 0;

                // Create the render target view.
                RenderTargetView = new RenderTargetView(device, RenderTargetTexture, renderTargetViewDesc);

                // Setup the description of the shader resource view.
                ShaderResourceViewDescription shaderResourceViewDesc = new ShaderResourceViewDescription()
                {
                    Format    = textureDesc.Format,
                    Dimension = ShaderResourceViewDimension.Texture2D,
                };
                shaderResourceViewDesc.Texture2D.MipLevels       = 1;
                shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;

                // Create the render target view.
                ShaderResourceView = new ShaderResourceView(device, RenderTargetTexture, shaderResourceViewDesc);

                // Initialize and Set up the description of the depth buffer.
                Texture2DDescription depthStencilDesc = new Texture2DDescription()
                {
                    Width             = 1024,
                    Height            = 1024,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.D24_UNorm_S8_UInt,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default,
                    BindFlags         = BindFlags.DepthStencil,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    OptionFlags       = ResourceOptionFlags.None
                };

                // Create the texture for the depth buffer using the filled out description.
                DepthStencilBuffer = new Texture2D(device, depthStencilDesc);

                // Initailze the depth stencil view description.
                DepthStencilViewDescription deothStencilViewDesc = new DepthStencilViewDescription()
                {
                    Format    = Format.D24_UNorm_S8_UInt,
                    Dimension = DepthStencilViewDimension.Texture2D
                };
                deothStencilViewDesc.Texture2D.MipSlice = 0;

                // Create the depth stencil view.
                DepthStencilView = new DepthStencilView(device, DepthStencilBuffer, deothStencilViewDesc);

                // Setup the viewport for rendering.
                ViewPort = new ViewportF()
                {
                    Width    = 1024.0f,
                    Height   = 1024.0f,
                    MinDepth = 0.0f,
                    MaxDepth = 1.0f,
                    X        = 0.0f,
                    Y        = 0.0f
                };

                return(true);
            }
            catch
            {
                return(false);
            }
        }