private void Init() { var pfd = new PixelFormatDescriptor(); pfd.Initialize(); this.hDC = WindowsOpenGLNative.GetDC(this.Handle); if (this.hDC == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } var iPixelformat = WindowsOpenGLNative.ChoosePixelFormat(this.hDC, ref pfd); if (iPixelformat == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // Set the pixel format if (!WindowsOpenGLNative.SetPixelFormat(this.hDC, iPixelformat, ref pfd)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // Create a new OpenGL rendering context this.hRC = WindowsOpenGLNative.wglCreateContext(this.hDC); if (this.hRC == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
public static extern Int32 DescribePixelFormat(IntPtr hdc, int iPixelFormat, uint nbytes, ref PixelFormatDescriptor ppfd);
public static extern bool SetPixelFormat(IntPtr hdc, int iPixelFormat, ref PixelFormatDescriptor ppfd);
public static extern int ChoosePixelFormat(IntPtr hdc, ref PixelFormatDescriptor ppfd);