Jump to content
  • Advertisement
Sign in to follow this  
Plerion

wglCreateContext returning 0

This topic is 3094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!