Exemplo n.º 1
0
        IntPtr WndEvents(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case USER32.WM_CREATE:
                return(IntPtr.Zero);

            case USER32.WM_ACTIVATEAPP:
                this.wActive = (wParam != IntPtr.Zero);
                return(IntPtr.Zero);

            case USER32.WM_CLOSE:
                USER32.DestroyWindow(this.wHandle);
                return(IntPtr.Zero);

            case USER32.WM_DESTROY:
                OPENGL32.wglMakeCurrent(this.dcHandle, IntPtr.Zero);
                OPENGL32.wglDeleteContext(this.wglContext);
                USER32.PostQuitMessage(0);
                return(IntPtr.Zero);

            default:
                return(USER32.DefWindowProc(hWnd, msg, wParam, lParam));
            }
        }
Exemplo n.º 2
0
        public void InitializeOpenGL( )
        {
            this.dcHandle = USER32.GetDC(this.wHandle);

            GDI32.PIXELFORMATDESCRIPTOR pfd = new GDI32.PIXELFORMATDESCRIPTOR( );
            pfd.nSize        = ( ushort )Marshal.SizeOf(pfd);
            pfd.nVersion     = 1;
            pfd.dwFlags      = (OPENGL32.PFD_DRAW_TO_WINDOW | OPENGL32.PFD_SUPPORT_OPENGL | OPENGL32.PFD_DOUBLEBUFFER);
            pfd.iPixelType   = OPENGL32.PFD_TYPE_RGBA;
            pfd.cColorBits   = 24;
            pfd.cDepthBits   = 16;
            pfd.cStencilBits = 8;
            pfd.iLayerType   = OPENGL32.PFD_MAIN_PLANE;

            int pixelFormat = GDI32.ChoosePixelFormat(this.dcHandle, pfd);

            GDI32.SetPixelFormat(this.dcHandle, pixelFormat, pfd);

            this.wglContext = OPENGL32.wglCreateContext(this.dcHandle);
            OPENGL32.wglMakeCurrent(this.dcHandle, this.wglContext);

            this.Initialize( );
        }