Checking OpenGL version


What's the preferred way to check the version of OpenGL? I'd like to check for 3.0 or later, preferablly as ealy as possible in app startup.

I noticed that the doc for OpenGLContext::setOpenGLVersionRequired says "Some platforms may ignore this value."

I didn't see any version checking code in the JUCE examples.




That function is your best bet - it'll be ignored on platforms like GLES, maybe, but should be ok on most platforms.


Thanks. I'm on Windows. What's setOpenGLVersionRequired supposed to do if the version requirement isn't met? (The doc doesn't say)

I did


and nothing happened. When I print out the GL version via glGetString(GL_VERSION), I get:

OpenGL version: 3.1.0 - Build



It seems like the code ignores the required version on Win32. In

we have the following constructor for NativeContext:

NativeContext (Component& component,
const OpenGLPixelFormat& pixelFormat,
void* contextToShareWith,
bool /*useMultisampling*/,

so the OpenGLVersion argument is ignored.


Jules, am I right that the function does nothing on Windows? Can we file a bug?


..I'm not sure what it would actually do with the required version on Windows?


I must have misunderstood the purpose of setOpenGLVersionRequired. It's supposed to set the current OpenGL version, rather than specify a minimum requirement, right?

Anyway, I suppose I can check for the OpenGL version within newOpenGLContextCreated and then let the main thread know and put up a dialog box. Does that sound good?


It's really just there for OSes where you can ask for a specific version, e.g. in GLES where you might want to use v1 or v2, which behave very differently. On Windows I can't really think why you'd ever need it, as the same code should work on all versions of GL.


Yeah, got it. Thanks!

How can I notify the main thread that the GL version is too old? Or can I make the GL context current from the main thread and check the version there?


Just set a flag or send a message, I guess.


I’m running into this issue now as well. Requesting 3.2 OpenGL on windows does not in fact create a context that’s guaranteed to support 3.2 functionality. The OpenGLContext::NativeContext constructor ignores the OpenGLVersion. What’s happening on windows with the old context creation function is that the driver will return the most recent context version that supports OpenGL 1.0 (you might get a 4.6 context but it might also be a 1.1 / 2.0 / 2.1 / 3.0 / 3.1 context if we’re unlucky)
I think JUCE should be changed to request explicit support for the version we’re asking it to create. You can do this using the WGL_ARB_create_context extension that has been introduced with OpenGL 3.0, see:
In short: JUCE is supposed to create a 1.0 context, load the context creation extension’s function, and then use that function to create a context supporting the requested version.

What’s the chance for JUCE to be updated to include explicit 3.2 support on windows?
And while we’re at it, would it be possible to add support to request a 3.2 compatibility profile on windows and 4.1 on both osx/windows?