// 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(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); } }