public WinGLContext(GraphicsMode format, WinWindowInfo window)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window", "Must point to a valid window.");
            }
            if (window.handle == IntPtr.Zero)
            {
                throw new ArgumentException("window", "Must be a valid window.");
            }

            Debug.Print("OpenGL will be bound to handle: {0}", window.handle);
            SelectGraphicsModePFD(format, (WinWindowInfo)window);
            Debug.Print("Setting pixel format... ");
            SetGraphicsModePFD(format, (WinWindowInfo)window);

            ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
            if (ContextHandle == IntPtr.Zero)
            {
                ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
            }
            if (ContextHandle == IntPtr.Zero)
            {
                throw new GraphicsContextException(
                          String.Format("Context creation failed. Wgl.CreateContext() error: {0}.",
                                        Marshal.GetLastWin32Error()));
            }

            Debug.Print("success! (id: {0})", ContextHandle);
        }
Exemple #2
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;
        }