Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

wglCreateContext returning 0

Started by Plerion Jun 30, 2010 at 5:18 PM 0 replies 850+ views
Original Post
Plerion
Plerion
Hello!

Im using OpenGL in a .NET-based application (just for fun). As the title mentions in the following function wglCreateContext returns 0:
private void Form1_Load(object sender, EventArgs e)        {            GL.PIXELFORMATDESC desc = new GL.PIXELFORMATDESC();            desc.nSize = (ushort)Marshal.SizeOf(desc);            desc.nVersion = 1;            desc.dwFlags = (uint)(GL.PixelFormatDesc.PFD_DRAW_TO_WINDOW | GL.PixelFormatDesc.PFD_DOUBLEBUFFER | GL.PixelFormatDesc.PFD_SUPPORT_OPENGL);            desc.iPixelType = (int)GL.PixelFormatDesc.PFD_TYPE_RGBA;            desc.cColorBits = 24;            desc.cAlphaBits = 8; // also tried with 0            desc.cDepthBits = 16;            desc.iLayerType = (int)GL.PixelFormatDesc.PFD_MAIN_PLANE;            hDCWindow = GL.GetDC(panel1.Handle);            int fmt = GL.ChoosePixelFormat(hDCWindow, ref desc);            if (GL.SetPixelFormat(hDCWindow, fmt, ref desc) == 0)                MessageBox.Show(Marshal.GetLastWin32Error().ToString());            hGLRC = GL.wglCreateContext(hDCWindow);            if(hGLRC == IntPtr.Zero)                MessageBox.Show(Marshal.GetLastWin32Error().ToString());            GL.wglMakeCurrent(hDCWindow, hGLRC);            timer.Interval = 22;            timer.Tick += Render;            timer.Start();        }


The errorcode is 2000 (incorrect pixelformat). SetPixelFormat returns true, and fmt is 4.

Isnt OpenGL running in FORMS-based applications?

Greetings
Plerion

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.