Exemple #1
0
        // Methods
        public virtual bool Initialize(string title, int width, int height, bool vSync, bool fullScreen, int testTimeSeconds)
        {
            bool result = false;

            if (Configuration == null)
            {
                Configuration = new DSystemConfiguration(title, width, height, fullScreen, vSync);
            }

            // Initialize Window.
            InitializeWindows(title);

            // Create the application wrapper object.
            DApplication = new DApplication();

            // Initialize the  application wrapper object.
            if (!DApplication.Initialize(Configuration, RenderForm.Handle))
            {
                return(false);
            }

            DPerfLogger.Initialize("RenderForm C# SharpDX: " + Configuration.Width + "x" + Configuration.Height + " VSync:" + DSystemConfiguration.VerticalSyncEnabled + " FullScreen:" + DSystemConfiguration.FullScreen + "   " + RenderForm.Text, testTimeSeconds, Configuration.Width, Configuration.Height);;

            // Create and initialize Timer.
            Timer = new DTimer();
            if (!Timer.Initialize())
            {
                MessageBox.Show("Could not initialize Timer object", "Error", MessageBoxButtons.OK);
                return(false);
            }

            return(result);
        }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the input object.  The input object will be used to handle reading the keyboard and mouse input from the user.
                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 camera object
                Camera = new DCamera();

                // Initialize a base view matrix with the camera for 2D user interface rendering.
                Camera.SetPosition(0.0f, 0.0f, -1.0f);
                Camera.Render();
                Matrix baseViewMatrix = Camera.ViewMatrix;

                // Set the initial position of the camera. (Since the ViewMatrix is already created from a base position.)
                Camera.SetPosition(40.0f, 2.0f, -7.0f);

                // Create the model object.
                TerrainModel = new DTerrain();

                // Initialize the terrain object.
                if (!TerrainModel.Initialize(D3D.Device, "heightmap01.bmp", "dirt03.bmp", "colorm01.bmp"))
                {
                    return(false);
                }

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

                // Set the initial position of the viewer to the same as the initial camera position.
                Position.SetPosition(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z);

                // Create the fps object.
                FPS = new DFPS();

                // Initialize the fps object.
                FPS.Initialize();

                // Create the cpu object.
                CPU = new DCPU();

                // Initialize the cpu object.
                CPU.Initialize();

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

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

                // Set the video card information in the text object.
                if (!Text.SetVideoCard(D3D.VideoCardDescription, D3D.VideoCardMemory, D3D.DeviceContext))
                {
                    return(false);
                }

                // Create the color shader object.
                TerrainShader = new DTerrainShader();

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

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

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

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

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

                // Get the size of the terrain as the minimap will require this information.
                int textureWidth  = TerrainModel.TextureWidth;
                int textureHeight = TerrainModel.TextureHeight;

                // Create the mini map object.
                MiniMap = new DMiniMapClass();

                // Initialize the mini map object.
                if (!MiniMap.Initialize(D3D.Device, windowHandle, configuration.Width, configuration.Height, baseViewMatrix, (float)(textureWidth - 1), (float)(textureHeight - 1)))
                {
                    return(false);
                }

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