public static PixelFormatDescriptor Create() { var pfd = new PixelFormatDescriptor(); pfd.nSize = (ushort)Marshal.SizeOf(typeof(PixelFormatDescriptor)); pfd.nVersion = 1; pfd.dwFlags = 0x04 | 0x20 | 0x01; // PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER pfd.iPixelType = 0; // PFD_TYPE_RGBA pfd.cColorBits = 32; pfd.cRedBits = pfd.cRedShift = pfd.cGreenBits = pfd.cGreenShift = pfd.cBlueBits = pfd.cBlueShift = 0; pfd.cAlphaBits = pfd.cAlphaShift = 0; pfd.cAccumBits = pfd.cAccumRedBits = pfd.cAccumGreenBits = pfd.cAccumBlueBits = pfd.cAccumAlphaBits = 0; pfd.cDepthBits = 24; pfd.cStencilBits = 8; pfd.cAuxBuffers = 0; pfd.iLayerType = 0; // PFD_MAIN_PLANE pfd.bReserved = 0; pfd.dwLayerMask = pfd.dwVisibleMask = pfd.dwDamageMask = 0; return(pfd); }
private void Form1_Load(object sender, EventArgs e) { // code var pfd = PixelFormatDescriptor.Create(); hdc = WinUser.GetDC(this.Handle); int format = GDI.ChoosePixelFormat(hdc, ref pfd); GDI.SetPixelFormat(hdc, format, ref pfd); hglrc = GL.wglCreateContext(hdc); if (hglrc == null) { throw new Exception("Failed to initialize OpenGL"); } GL.wglMakeCurrent(hdc, hglrc); GL.glClearColor(0.5f, 0.0f, 0.0f, 1.0f); LoadGlCompileShader(); }
public static extern int ChoosePixelFormat(IntPtr hdc, [In] ref PixelFormatDescriptor pfd);
public static extern bool SetPixelFormat(IntPtr hdc, int format, ref PixelFormatDescriptor pfd);