예제 #1
0
        void ISupportInitialize.EndInit()
        {
            hDC = VtsGL.GetDC(Handle);

            // pixel format
            VtsGL.PIXELFORMATDESCRIPTOR pfd = new VtsGL.PIXELFORMATDESCRIPTOR();
            pfd.Init();
            pfd.nVersion     = 1;
            pfd.dwFlags      = 4 | 32 | 1;
            pfd.iPixelType   = 0;
            pfd.cColorBits   = (byte)24;
            pfd.cDepthBits   = 0;
            pfd.cStencilBits = 0;
            pfd.iLayerType   = 0;
            int iPixelformat;

            if ((iPixelformat = VtsGL.ChoosePixelFormat(hDC, pfd)) == 0)
            {
                throw new Exception("Failed ChoosePixelFormat.");
            }
            if (VtsGL.SetPixelFormat(hDC, iPixelformat, pfd) == 0)
            {
                throw new Exception("Failed SetPixelFormat.");
            }

            // basic render context
            hRC = VtsGL.wglCreateContext(hDC);
            VtsGL.wglMakeCurrent(hDC, hRC);

            // reinitialize context to modern version
            int[] attributes =
            {
                0x2091, 3,          // major version
                0x2092, 3,          // minor version
#if DEBUG
                0x2094, 0x0001,     // debug context
#endif
                0x9126, 0x00000001, // core profile
                0
            };
            var hRC2 = VtsGL.CreateContextAttribsARB(hDC, IntPtr.Zero, attributes);

            VtsGL.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);
            VtsGL.wglDeleteContext(hRC);
            VtsGL.wglMakeCurrent(hDC, hRC2);
            hRC = hRC2;

            // event
            Init?.Invoke(this, new EventArgs());

            // update size
            OnSizeChanged(null);

            // timer
            timer.Interval = 16;
            timer.Enabled  = true;
            timer.Tick    += timerDrawing_Tick;
        }
예제 #2
0
 protected override void OnPaint(PaintEventArgs e)
 {
     VtsGL.wglMakeCurrent(hDC, hRC);
     //VtsGL.glViewport(0, 0, Width, Height);
     //VtsGL.glClearColor(1, 0, 0, 0);
     //VtsGL.glClear(0x4000); // GL_COLOR_BUFFER_BIT
     Draw?.Invoke(this, e);
     VtsGL.SwapBuffers(hDC);
 }
예제 #3
0
        void IDisposable.Dispose()
        {
            VtsGL.wglMakeCurrent(hDC, hRC);
            Fin?.Invoke(this, new EventArgs());
            VtsGL.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero);

            VtsGL.ReleaseDC(Handle, hDC);
            if (hRC != IntPtr.Zero)
            {
                VtsGL.wglDeleteContext(hRC);
                hRC = IntPtr.Zero;
            }
        }
예제 #4
0
 protected override void OnPaint(PaintEventArgs e)
 {
     VtsGL.wglMakeCurrent(hDC, hRC);
     Draw?.Invoke(this, e);
     VtsGL.SwapBuffers(hDC);
 }