コード例 #1
0
        public WinGLContext(GraphicsMode format, WinWindow window)
        {
            Debug.Print("OpenGL will be bound to handle: {0}", window.WinHandle);
            SelectGraphicsModePFD(format, window);
            Debug.Print("Setting pixel format... ");
            SetGraphicsModePFD(format, window);

            ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
            if (ContextHandle == IntPtr.Zero)
            {
                ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
            }
            if (ContextHandle == IntPtr.Zero)
            {
                throw new GraphicsContextException("Context creation failed. Error: " + Marshal.GetLastWin32Error());
            }

            if (!Wgl.wglMakeCurrent(window.DeviceContext, ContextHandle))
            {
                throw new GraphicsContextException("Failed to make context current. " +
                                                   "Error: " + Marshal.GetLastWin32Error());
            }

            dc = Wgl.wglGetCurrentDC();
            Wgl.LoadEntryPoints();
            vsync_supported = Wgl.wglSwapIntervalEXT != null;
        }