Posted by Ritesh on Sat 5 Jan 19:46
report abuse | download | new post
- public bool InitializeGraphics()
- {
- try
- {
- Cursor.Hide();
- AdapterInformation ai = Manager.Adapters.Default;
- Caps caps = Manager.GetDeviceCaps(ai.Adapter, DeviceType.Hardware);
- presentParams.Windowed = !doFullscreen;
- presentParams.SwapEffect = SwapEffect.Discard; // Discard the frames
- presentParams.EnableAutoDepthStencil = true; // Turn on a Depth stencil
- presentParams.AutoDepthStencilFormat = DepthFormat.D16; // And the stencil format
- presentParams.BackBufferCount = 1;
- presentParams.BackBufferWidth = m_dwWidth; //screen width
- presentParams.BackBufferHeight = m_dwHeight; //screen height
- presentParams.BackBufferFormat = ai.CurrentDisplayMode.Format; //color depth
- presentParams.DeviceWindow = this;
- presentParams.MultiSample = MultiSampleType.None; //anti-aliasing
- presentParams.PresentationInterval = PresentInterval.Immediate; //don't wait... draw right away
- // Check if gfx card can do HW T&L
- CreateFlags flags = CreateFlags.SoftwareVertexProcessing;
- if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
- flags = CreateFlags.HardwareVertexProcessing;
- // Check if gfx card can do rasterization etc
- if (caps.DeviceCaps.SupportsPureDevice)
- flags |= CreateFlags.PureDevice;
- // Add event handler to cancel device resize
- this.OnCreateDevice(device, null);
- this.OnResetDevice(device, null);
- return true;
- }
- catch (DirectXException)
- {
- // Catch any errors and return a failure
- return false;
- }
- }
- void OnDeviceResizing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- Device device = sender as Device;
- // Don't let the device automatically resize itself to the window dimensions in fullscreen mode
- // This is needed because at this point the application hasn't gained control of the device yet, leading to a crash.
- e.Cancel = !device.PresentationParameters.Windowed;
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.