Beispiel #1
0
        public override void MakeCurrent(IWindowInfo window)
        {
            bool success;

            if (window != null)
            {
                if (((WinWindowInfo)window).handle == IntPtr.Zero)
                {
                    throw new ArgumentException("window", "Must point to a valid window.");
                }

                success = Wgl.wglMakeCurrent(((WinWindowInfo)window).DeviceContext, ContextHandle);
            }
            else
            {
                success = Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
            }

            if (!success)
            {
                throw new GraphicsContextException(String.Format(
                                                       "Failed to make context {0} current. Error: {1}", this, Marshal.GetLastWin32Error()));
            }
            dc = Wgl.wglGetCurrentDC();
        }
Beispiel #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;
        }