private void Form_Load(object sender, EventArgs e) { Form form = (Form)sender; System.Diagnostics.Debug.Assert(Direct3D == null); Direct3D = new Direct3D(); int nAdapter = Direct3D.Adapters[0].Adapter; Capabilities devCaps = Direct3D.GetDeviceCaps(nAdapter, DeviceType.Hardware); // the flags for our Direct3D device. Use software rendering by // default CreateFlags devFlags = CreateFlags.SoftwareVertexProcessing; // use hardware vertex processing if supported if ((devCaps.DeviceCaps & DeviceCaps.HWTransformAndLight) == DeviceCaps.HWTransformAndLight) { devFlags = CreateFlags.HardwareVertexProcessing; } // use pure device (whatever that is) if supported if ((devCaps.DeviceCaps & DeviceCaps.PureDevice) == DeviceCaps.PureDevice) { devFlags |= CreateFlags.PureDevice; } DisplayMode displayMode = Direct3D.GetAdapterDisplayMode(nAdapter); System.Diagnostics.Debug.Assert(PresentParams == null); PresentParams = new PresentParameters(); PresentParams.BackBufferWidth = form.ClientSize.Width; PresentParams.BackBufferHeight = form.ClientSize.Height; PresentParams.BackBufferFormat = displayMode.Format; PresentParams.BackBufferCount = 1; PresentParams.Windowed = true; PresentParams.SwapEffect = SwapEffect.Discard; PresentParams.AutoDepthStencilFormat = Format.D16; PresentParams.EnableAutoDepthStencil = true; PresentParams.DeviceWindowHandle = form.Handle; System.Diagnostics.Debug.Assert(Device == null); // create the Direct3D device Device = new SDXDevice(new Device(Direct3D, nAdapter, DeviceType.Hardware, form.Handle, devFlags, PresentParams), Form.ClientSize.Width / 640.0f, Form.ClientSize.Height / 480.0f); ResetDevice(); using (System.Drawing.Font baseFont = new System.Drawing.Font("Arial Black", 18, FontStyle.Bold)) { System.Diagnostics.Debug.Assert(d3dFont == null); d3dFont = new Font(Device, baseFont); } Application.Idle += OnApplicationIdle; }
private static MyAdapterInfo[] GetAdaptersList(Direct3D d3d) { MyAdapterInfo[] result = new MyAdapterInfo[d3d.AdapterCount]; for (var i = 0; i < result.Length; i++) { result[i] = new MyAdapterInfo(); var details = d3d.GetAdapterIdentifier(i); var currentDisplayMode = d3d.GetAdapterDisplayMode(i); result[i].CurrentDisplayMode = new MyDisplayMode { Height = currentDisplayMode.Height, Width = currentDisplayMode.Width, RefreshRate = currentDisplayMode.RefreshRate, AspectRatio = currentDisplayMode.AspectRatio }; result[i].DeviceName = details.DeviceName; result[i].VendorId = details.VendorId; result[i].DeviceId = details.DeviceId; result[i].Description = details.Description; result[i].Name = details.Description + " (" + details.DeviceName.Replace("\\", "").Replace(".", "") + ")"; result[i].SupportedDisplayModes = new MyDisplayMode[0]; bool retry = false; try { result[i].SupportedDisplayModes = GetSupportedDisplayModes(d3d, i); } catch (SharpDXException dxgiException) { if (dxgiException.ResultCode != ResultCode.NotAvailable) { throw; } m_backbufferFormat = Format.A8B8G8R8; retry = true; } if (retry) { try { result[i].SupportedDisplayModes = GetSupportedDisplayModes(d3d, i); } catch (SharpDXException dxgiException) { if (dxgiException.ResultCode != ResultCode.NotAvailable) { throw; } } } } MyGraphicTest test = new MyGraphicTest(); test.TestDX(d3d, ref result); return(result); }
public void Initialize(int monitor) { var direct3d = new Direct3D(); _displayMode = direct3d.GetAdapterDisplayMode(monitor); //https://stackoverflow.com/questions/30021274/capture-screen-using-directx _device = CreateDevice(direct3d, monitor, _displayMode); _surface = Surface.CreateOffscreenPlain(_device, _displayMode.Width, _displayMode.Height, Format.A8R8G8B8, Pool.SystemMemory); _screenHelper = new ScreenHelper(); _currentMonitor = monitor; }
private static PresentParameters GetParameters(Direct3D d3d, IntPtr windowHandle) { var mode = d3d.GetAdapterDisplayMode(0); return(new PresentParameters() { BackBufferWidth = mode.Width, BackBufferHeight = mode.Height, BackBufferFormat = mode.Format, DeviceWindowHandle = windowHandle, SwapEffect = SwapEffect.Discard, Windowed = true, PresentationInterval = PresentInterval.Immediate }); }