private void initPixelFormat() { int pixelFormatIndex = 0; WGL.PIXELFORMATDESCRIPTOR pixelFormatDescriptor = new WGL.PIXELFORMATDESCRIPTOR(); WGL.ZeroPixelDescriptor(ref pixelFormatDescriptor); pixelFormatDescriptor.nVersion = 1; pixelFormatDescriptor.dwFlags = (WGL.PFD_DRAW_TO_WINDOW | WGL.PFD_SUPPORT_OPENGL | WGL.PFD_DOUBLEBUFFER); pixelFormatDescriptor.iPixelType = (byte)(WGL.PFD_TYPE_RGBA); pixelFormatDescriptor.cColorBits = 32; pixelFormatDescriptor.cDepthBits = 32; pixelFormatDescriptor.iLayerType = (byte)(WGL.PFD_MAIN_PLANE); pixelFormatDescriptor.cStencilBits = 32; pixelFormatIndex = WGL.ChoosePixelFormat(m_uint_DC, ref pixelFormatDescriptor); if (pixelFormatIndex == 0) { MessageBox.Show("Unable to retrieve pixel format"); return; } if (WGL.SetPixelFormat(m_uint_DC, pixelFormatIndex, ref pixelFormatDescriptor) == 0) { MessageBox.Show("Unable to set pixel format"); return; } }
private static int smethod_0(IntPtr hdc, PixelFormatDescriptor pfd) { int iPixelFormat = WGL.ChoosePixelFormat(hdc, ref pfd); if (iPixelFormat == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } if (WGL.SetPixelFormat(hdc, iPixelFormat, ref pfd) == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(iPixelFormat); }
private void Form1_Load(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); hdc = g.GetHdc(); PixelFormatDescriptor m_pfd = new PixelFormatDescriptor(); m_pfd.Flags = (uint)(WGL.PFD_FLAGS.DOUBLEBUFFER | WGL.PFD_FLAGS.DRAW_TO_WINDOW | WGL.PFD_FLAGS.SUPPORT_OPENGL | WGL.PFD_FLAGS.TYPE_RGBA); m_pfd.PixelType = 0; m_pfd.ColorBits = 24; m_pfd.DepthBits = 32; m_pfd.LayerType = 0; Int32 pf = m_wgl.ChoosePixelFormat(hdc, m_pfd); if (pf == 0) { throw new Exception("ChoosePixelFormat failed"); } Int32 spf = m_wgl.SetPixelFormat(hdc, pf, m_pfd); if (spf != 1) { throw new Exception("SetPixelFormat failed"); } IntPtr ctx = m_wgl.CreateContext(hdc); m_wgl.MakeCurrent(hdc, ctx); m_gl.MatrixMode(GL.GL_FLAGS.PROJECTION); m_gl.Frustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F); m_gl.MatrixMode(GL.GL_FLAGS.MODELVIEW); m_gl.Translatef(0.0F, 0.0F, -2.0F); m_gl.Rotatef(30.0F, 1.0F, 0.0F, 0.0F); m_gl.Rotatef(30.0F, 0.0F, 1.0F, 0.0F); m_gl.Enable(GL.GL_FLAGS.DEPTH_TEST); m_gl.Enable(GL.GL_FLAGS.COLOR_MATERIAL); m_gl.Enable(GL.GL_FLAGS.LIGHTING); m_gl.Enable(GL.GL_FLAGS.LIGHT0); m_gl.ColorMaterial(GL.GL_FLAGS.FRONT_AND_BACK, GL.GL_FLAGS.AMBIENT_AND_DIFFUSE); this.Invalidate(); }
public static RenderingContext FromWindowHandle( IntPtr windowHandle, int pixelFormatIndex) { IntPtr dc = WGL.GetDC(windowHandle); WGL.wglSwapBuffers(dc); PixelFormatDescriptor empty = PixelFormatDescriptor.Empty; if (WGL.SetPixelFormat(dc, pixelFormatIndex, ref empty) == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } IntPtr context = WGL.wglCreateContext(dc); if (context == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return(new RenderingContext(windowHandle, dc, false, context, pixelFormatIndex)); }