public CompatibleDeviceContext(DeviceContext deviceContext, uint width, uint height) { _DC = WinGDI.CreateCompatibleDeviceContext(deviceContext.DeviceContextHandle); BitmapHandle = WinGDI.CreateCompatibleBitmap(deviceContext.DeviceContextHandle, width, height); _ = WinGDI.DeviceContextSetBitmap(_DC, BitmapHandle); Width = width; Height = height; }
public GLContext(WindowProperties properties, object deviceContext) { hDc = WinUser.GetDC((IntPtr)deviceContext); IntPtr hrc = WinGDI.wglCreateContext(hDc); if (hrc.ToInt32() != 0) { if (!WinGDI.wglMakeCurrent(hDc, hrc)) { Log.Error("Failed setting OpenGL context!"); Log.Assert(() => false); } } else { Log.Error("Failed creating OpenGL context!"); Log.Assert(() => false); } }
public uint CopyBitsFromBuffer(uint[] buffer) { if (buffer.Length < Width * Height) { return(87); } WinGDI.BitmapInfo bitmapInfo = new WinGDI.BitmapInfo(Width, Height); return(WinGDI.CopyBufferBitsToDeviceContext( _DC, BitmapHandle, 0, Height, ref buffer[0], in bitmapInfo, 0 )); }
public override void Dispose() { if (!_Disposed) { _Disposed = true; GC.SuppressFinalize(this); if (_DC != Handle.Zero) { _ = WinGDI.DeleteDeviceContext(_DC); } if (BitmapHandle != Handle.Zero) { _ = WinGDI.DeleteBitmap(BitmapHandle); } } }
public void Present() { WinGDI.SwapBuffers(hDc); }
private bool PlatformInit() { WNDCLASS winClass = new WNDCLASS(); winClass.style = WinUser.CS_HREDRAW | WinUser.CS_VREDRAW | WinUser.CS_OWNDC; proc = WndProc; winClass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(proc); winClass.lpszClassName = "Sparky Win32 Window"; winClass.hCursor = WinUser.LoadCursorW(IntPtr.Zero, WinUser.IDC_ARROW); winClass.hIcon = WinUser.LoadIconW(IntPtr.Zero, WinUser.IDI_WINLOGO); if (WinUser.RegisterClassW(ref winClass) == 0) { Log.Error("Could not register Win32 class!"); return(false); } RECT size = new RECT(0, 0, (int)properties.width, (int)properties.height); WinUser.AdjustWindowRectEx(ref size, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, false, WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE); hWnd = WinUser.CreateWindowExW(WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE, winClass.lpszClassName, title, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, (int)(WinUser.GetSystemMetrics(WinUser.SM_CXSCREEN) / 2 - properties.width / 2), (int)(WinUser.GetSystemMetrics(WinUser.SM_CYSCREEN) / 2 - properties.height / 2), (int)(size.right + (-size.left)), (int)(size.bottom + (-size.top)), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); if (hWnd.ToInt32() == 0) { Log.Error("Could not create window!"); return(false); } RegisterWindowClass(hWnd, this); hDc = WinUser.GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd = GetPixelFormat(); int pixelFormat = WinGDI.ChoosePixelFormat(hDc, ref pfd); if (pixelFormat != 0) { if (!WinGDI.SetPixelFormat(hDc, pixelFormat, ref pfd)) { Log.Error("Failed setting pixel format!"); return(false); } } else { Log.Error("Failed choosing pixel format!"); return(false); } Context.Create(properties, hWnd); WinUser.ShowWindow(hWnd, WinUser.SW_SHOW); WinUser.SetFocus(hWnd); return(true); }