public Main() { _graphicsDeviceManager = new GraphicsDeviceManager(this) { SynchronizeWithVerticalRetrace = false, PreferredBackBufferWidth = PreferredSize.Width, PreferredBackBufferHeight = PreferredSize.Height, PreferredBackBufferFormat = PixelFormat.R8G8B8A8.UNormSRgb, //DeviceCreationFlags = DeviceCreationFlags.Debug }; IsFixedTimeStep = false; Content.RootDirectory = "Content"; var directInput = new DirectInput(); _keyboard = new Keyboard(directInput); _keyboard.Acquire(); _mouse = new Mouse(directInput); _mouse.Acquire(); }
internal bool Initialize(SystemConfiguration 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(); // 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. _Keyboard.SetCooperativeLevel(windowsHandle, CooperativeLevel.Foreground | CooperativeLevel.Exclusive); // Now acquire the keyboard. if (_Keyboard.Acquire().Failure) return false; // 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); // Now acquire the mouse. if (_Mouse.Acquire().Failure) return false; return true; }
/// <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); }