public static ContextHandle CreateContextCurrent(IntPtr hwnd) { var context = ContextHandle.Zero; var hdc = Win32Helper.GetDC(hwnd);//取得设备上下文 PixelFormatDescriptor pfd; pfd.Size = 40; pfd.Version = 1; pfd.Flags = PixelFormatDescriptorFlags.DRAW_TO_WINDOW | PixelFormatDescriptorFlags.SUPPORT_OPENGL | PixelFormatDescriptorFlags.DOUBLEBUFFER; pfd.PixelType = PixelType.RGBA; pfd.ColorBits = 32; pfd.DepthBits = 16; pfd.StencilBits = 8; int pixelFormat; unsafe { PixelFormatDescriptor *ppfd = &pfd; pixelFormat = Win32Helper.ChoosePixelFormat(hdc, (IntPtr)ppfd); //选择像素格式 Win32Helper.SetPixelFormat(hdc, pixelFormat, (IntPtr)ppfd); //设置像素格式 context = new ContextHandle(hdc, Win32Helper.CreateContext(hdc)); //建立OpenGL渲染上下文 MakeCurrentContext(context); //激活当前渲染上下文 _contexts[context.HDC] = context; } return(context); }