protected Device CreateDevice(int width, int height, bool windowed) { var d3D9 = CreateDirect3D(); if (d3D9 == null) { return(null); } var caps = d3D9.GetDeviceCaps(0, DeviceType.Hardware); var vp = CreateFlags.Multithreaded | (caps.DeviceCaps.HasFlag(DeviceCaps.HWTransformAndLight) ? CreateFlags.HardwareVertexProcessing : CreateFlags.SoftwareVertexProcessing); if (caps.VertexShaderVersion < new Version(2, 0) || caps.PixelShaderVersion < new Version(2, 0)) { Debug.Print("Warning - Your graphic card does not support vertex and pixel shaders version 2.0"); } var format = (windowed) ? Format.Unknown : Format.A8R8G8B8; var pp = new PresentParameters { BackBufferWidth = width, BackBufferHeight = height, BackBufferFormat = format, BackBufferCount = 1, Multisample = MultisampleType.None, MultisampleQuality = 0, SwapEffect = SwapEffect.Discard, DeviceWindowHandle = MainWindow.Handle, Windowed = windowed, EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D24S8, PresentFlags = PresentFlags.None, FullScreenRefreshRateInHertz = 0, PresentationInterval = PresentInterval.Immediate }; Device device = null; try { device = new Device(d3D9, 0, DeviceType.Hardware, MainWindow.Handle, vp, pp); } catch (Exception ex) { Debug.Print("Failed to create Device - {0}", ex.Message); } d3D9.Dispose(); System.Diagnostics.Debug.Assert(device != null, "device != null"); System.Diagnostics.Debug.Assert(device.ComPointer != IntPtr.Zero); try { device.GetRenderState(RenderState.Lighting); } catch (Exception ex) { Debug.Print("Error in {0} - {1}\n{2}", ex.TargetSite, ex.Message, ex.StackTrace); return(null); } device.Material = new Material { Diffuse = Color.White }; return(device); }
protected Device CreateDevice(int width, int height, bool windowed) { var d3D9 = CreateDirect3D(); if (d3D9 == null) { return null; } var caps = d3D9.GetDeviceCaps(0, DeviceType.Hardware); var vp = CreateFlags.Multithreaded | (caps.DeviceCaps.HasFlag(DeviceCaps.HWTransformAndLight) ? CreateFlags.HardwareVertexProcessing : CreateFlags.SoftwareVertexProcessing); if (caps.VertexShaderVersion < new Version(2, 0) || caps.PixelShaderVersion < new Version(2, 0)) { Debug.Print("Warning - Your graphic card does not support vertex and pixel shaders version 2.0"); } var format = (windowed) ? Format.Unknown : Format.A8R8G8B8; var pp = new PresentParameters { BackBufferWidth = width, BackBufferHeight = height, BackBufferFormat = format, BackBufferCount = 1, Multisample = MultisampleType.None, MultisampleQuality = 0, SwapEffect = SwapEffect.Discard, DeviceWindowHandle = MainWindow.Handle, Windowed = windowed, EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D24S8, PresentFlags = PresentFlags.None, FullScreenRefreshRateInHertz = 0, PresentationInterval = PresentInterval.Immediate }; Device device = null; try { device = new Device(d3D9, 0, DeviceType.Hardware, MainWindow.Handle, vp, pp); } catch (Exception ex) { Debug.Print("Failed to create Device - {0}", ex.Message); } d3D9.Dispose(); System.Diagnostics.Debug.Assert(device != null, "device != null"); System.Diagnostics.Debug.Assert(device.ComPointer != IntPtr.Zero); try { device.GetRenderState(RenderState.Lighting); } catch (Exception ex) { Debug.Print("Error in {0} - {1}\n{2}", ex.TargetSite, ex.Message, ex.StackTrace); return null; } device.Material = new Material { Diffuse = Color.White }; return device; }