This object can render texture onto screen.
Ejemplo n.º 1
0
        /// <summary>
        /// Initializes SlimDX and input devices.
        /// </summary>
        /// <param name="caption">Window caption string.</param>
        public FrameworkForm(string caption)
            : base(caption)
        {
            SwapChainDescription description = new SwapChainDescription()
            {
                BufferCount       = 1,
                Flags             = SwapChainFlags.None,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(ClientSize.Width, ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle      = Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            try
            {
#if DEBUG
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out graphicsDevice, out swapChain);
#else
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out graphicsDevice, out swapChain);
#endif
            }
            catch
            {
                MessageBox.Show("An error has occurred during initialization process.");
                Environment.Exit(0);
            }
            finally
            {
                if (graphicsDevice.FeatureLevel != FeatureLevel.Level_11_0)
                {
                    MessageBox.Show("This program requires DirectX 11. Your version is " + graphicsDevice.FeatureLevel.ToString() + ".");
                    Environment.Exit(0);
                }
            }

            Factory factory = swapChain.GetParent <Factory>();
            factory.SetWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
            KeyDown += (o, e) =>
            {
                // Fixes Alt-Enter keyboard input bug in SlimDX.
                if (e.Alt && e.KeyCode == Keys.Enter)
                {
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;
                }

                // Makes screenshot.
                if (e.KeyCode == Keys.F12)
                {
                    MakeScreenshot(Application.StartupPath);
                }
            };

            SizeChanged += (o, e) =>
            {
                // Dispose old resources.
                if (renderTargetView != null)
                {
                    renderTargetView.Dispose();
                }
                if (backBufferTexture != null)
                {
                    backBufferTexture.Dispose();
                }

                // Resize buffers.
                swapChain.ResizeBuffers(1, ClientSize.Width, ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);

                InitializeOutputMerger();

                camera.UpdateProjection();

                postProcess.Initialize(ClientSize.Width, ClientSize.Height);
            };

            fillMode = FillMode.Solid;
            InitializeOutputMerger();

            // Initializes input devices.
            DirectInput directInput = new DirectInput();
            keyboard = new Keyboard(directInput);
            keyboard.Acquire();
            mouse = new Mouse(directInput);
            mouse.Acquire();

            camera       = new Camera(graphicsDevice, new Vector3(50, 50, 50), new Vector3(0, 0, 0), 0.1f, 1000.0f);
            textures     = new List <TexturePack>();
            postProcess  = new PostProcess(graphicsDevice, ClientSize.Width, ClientSize.Height);
            quadRenderer = new QuadRenderer(graphicsDevice);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes SlimDX and input devices.
        /// </summary>
        /// <param name="caption">Window caption string.</param>
        public FrameworkForm(string caption)
            : base(caption)
        {
            SwapChainDescription description = new SwapChainDescription()
            {
                BufferCount = 1,
                Flags = SwapChainFlags.None,
                IsWindowed = true,
                ModeDescription = new ModeDescription(ClientSize.Width, ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
                OutputHandle = Handle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect = SwapEffect.Discard,
                Usage = Usage.RenderTargetOutput
            };

            try
            {
#if DEBUG
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, description, out graphicsDevice, out swapChain);
#else
                Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out graphicsDevice, out swapChain);
#endif
            }
            catch
            {
                MessageBox.Show("An error has occurred during initialization process.");
                Environment.Exit(0);
            }
            finally
            {
                if (graphicsDevice.FeatureLevel != FeatureLevel.Level_11_0)
                {
                    MessageBox.Show("This program requires DirectX 11. Your version is " + graphicsDevice.FeatureLevel.ToString() + ".");
                    Environment.Exit(0);
                }
            }

            Factory factory = swapChain.GetParent<Factory>();
            factory.SetWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
            KeyDown += (o, e) =>
            {
                // Fixes Alt-Enter keyboard input bug in SlimDX.
                if (e.Alt && e.KeyCode == Keys.Enter)
                    swapChain.IsFullScreen = !swapChain.IsFullScreen;

                // Makes screenshot.
                if (e.KeyCode == Keys.F12)
                    MakeScreenshot(Application.StartupPath);
            };

            SizeChanged += (o, e) =>
            {
                // Dispose old resources.
                if (renderTargetView != null)
                    renderTargetView.Dispose();
                if (backBufferTexture != null)
                    backBufferTexture.Dispose();

                // Resize buffers.
                swapChain.ResizeBuffers(1, ClientSize.Width, ClientSize.Height, Format.R8G8B8A8_UNorm, SwapChainFlags.None);

                InitializeOutputMerger();

                camera.UpdateProjection();

                postProcess.Initialize(ClientSize.Width, ClientSize.Height);
            };

            fillMode = FillMode.Solid;
            InitializeOutputMerger();

            // Initializes input devices.
            DirectInput directInput = new DirectInput();
            keyboard = new Keyboard(directInput);
            keyboard.Acquire();
            mouse = new Mouse(directInput);
            mouse.Acquire();

            camera = new Camera(graphicsDevice, new Vector3(50, 50, 50), new Vector3(0, 0, 0), 0.1f, 1000.0f);
            textures = new List<TexturePack>();
            postProcess = new PostProcess(graphicsDevice, ClientSize.Width, ClientSize.Height);
            quadRenderer = new QuadRenderer(graphicsDevice);
        }