Jump to content
  • Advertisement
Sign in to follow this  
Seabolt

OpenGL wglCreateContext return INVALID_OPERATION

This topic is 2699 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

Hey guys, I'm currently having an issue where when I call wglCreateContext and then call glGetError() I get an INVALID_OPERATION enum.

It doesn't fail the call though and I get an HGLRC of 0x00010000. ChoosePixelFormat returns a valid format( 1 ), and SetPixelFormat runs fine. I'm running on a laptop with nVidia Quadro FX 1600M on Win7, any ideas would be appreciated. Here's some code:


//////////////////////////////////////////////////////////////////////////
// Platform Specific Initialization (Windows)
#if USING_WINDOWS

// Store the HWND
m_handleWindowHandle = programWindow->GetWindowHandle();

// Do a NULL check if we are in Debug
ASSERT_NULL( m_handleWindowHandle );

// Get the Device Context
m_handleDeviceContext = programWindow->GetHDC();

// Null check the DC
ASSERT_NULL( m_handleDeviceContext );

//////////////////////////////////////////////////////////////////////////
// Set the pixel format
m_tPixelFormat.nSize = sizeof( PIXELFORMATDESCRIPTOR ); // Size of the PFD
m_tPixelFormat.nVersion = 1; // Set the version number
m_tPixelFormat.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
m_tPixelFormat.iPixelType = PFD_TYPE_RGBA; // Set the color format
m_tPixelFormat.cColorBits = 32; // Set the color depth
m_tPixelFormat.cDepthBits = 24; // Set the depth buffer depth
m_tPixelFormat.cStencilBits = 8; // Set the stencil buffer depth
m_tPixelFormat.iLayerType = PFD_MAIN_PLANE; // Set the layer for the app

// See if there is a pixel format that will match our requests
int nPixelFormat = 0;
ASSERT_FALSE( nPixelFormat = ChoosePixelFormat( m_handleDeviceContext,
&m_tPixelFormat ) );

ASSERT_FALSE( SetPixelFormat( m_handleDeviceContext,
nPixelFormat,
&m_tPixelFormat ) );

//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
// So far so good... Now we try to create our RenderContext (HRC)
m_handleGLRenderContext = wglCreateContext( m_handleDeviceContext );
ASSERT_NULL( m_handleGLRenderContext );

GLenum error = glGetError();
if( error != GL_NO_ERROR )
{
while( glGetError() != GL_NO_ERROR )
{
error = glGetError(); // Will always return 1282
int x = 0;
x++;
}
}


Share this post


Link to post
Share on other sites
Advertisement
wglCreateContext only creates the context, you need to call wglMakeCurrent to activate it. It is not wglCreateContext that is generating the error, it is glGetError. Since you're calling it without an active context, it returns GL_INVALID_OPERATION because it is an invalid operation to call it, or any, OpenGL function without an active rendering context.

Share this post


Link to post
Share on other sites
Another question though, when I check the GetLastError after glewInit I get 127 which meant it couldn't find the proc address, but glew itself doesn't return an error and I can create a valid HGLRC, should I be worried about this?

Share this post


Link to post
Share on other sites
It probably just tries to load a function your driver doesn't support. If you want to know for sure, step through it with a debugger and find out where the error is set.

Share this post


Link to post
Share on other sites
I don't know whether you are doing it elsewhere or not, but you should zero-out your m_tPixelFormat just to make sure ChoosePixelFormat doesn't blow up.

I use memset
memset(m_tPixelFormat, 0, sizeof(PIXELFORMATDESCRIPTOR));

some people use ZeroMemory.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!