# Checking OpenGL version

**URL:** <https://forum.juce.com/t/checking-opengl-version/14035>\
**Category:** General JUCE discussion\
**Created:** [December 14, 2014, 6:40pm UTC](https://forum.juce.com/t/checking-opengl-version/14035 "2014-12-14T18:40:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tayholliday](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tayholliday/32/589_2.png) [@tayholliday](https://forum.juce.com/u/tayholliday)\
**Post date:** [December 14, 2014, 6:40pm UTC](https://forum.juce.com/t/checking-opengl-version/14035/1 "2014-12-14T18:40:40Z")

</div>

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

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

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

&nbsp;

thanks!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 14, 2014, 6:50pm UTC](https://forum.juce.com/t/checking-opengl-version/14035/2 "2014-12-14T18:50:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tayholliday](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tayholliday/32/589_2.png) [@tayholliday](https://forum.juce.com/u/tayholliday)\
**Post date:** [December 15, 2014, 3:15am UTC](https://forum.juce.com/t/checking-opengl-version/14035/3 "2014-12-15T03:15:44Z")

</div>

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

I did

```
openGLContext.setOpenGLVersionRequired(OpenGLContext::openGL3_2);
```

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

```
OpenGL version: 3.1.0 - Build 9.17.10.3347
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![tayholliday](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tayholliday/32/589_2.png) [@tayholliday](https://forum.juce.com/u/tayholliday)\
**Post date:** [December 15, 2014, 4:17am UTC](https://forum.juce.com/t/checking-opengl-version/14035/4 "2014-12-15T04:17:16Z")

</div>

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

https://github.com/julianstorer/JUCE/blob/da8e3c53b69e7210fe20a40a6b4588af4ff47d08/modules/juce\_opengl/native/juce\_OpenGL\_win32.h

we have the following constructor for NativeContext:

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

so the OpenGLVersion argument is ignored.

---

<div class="post-metadata">

**Author:** ![tayholliday](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tayholliday/32/589_2.png) [@tayholliday](https://forum.juce.com/u/tayholliday)\
**Post date:** [December 18, 2014, 11:16pm UTC](https://forum.juce.com/t/checking-opengl-version/14035/5 "2014-12-18T23:16:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 19, 2014, 8:26am UTC](https://forum.juce.com/t/checking-opengl-version/14035/6 "2014-12-19T08:26:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tayholliday](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tayholliday/32/589_2.png) [@tayholliday](https://forum.juce.com/u/tayholliday)\
**Post date:** [December 20, 2014, 3:34am UTC](https://forum.juce.com/t/checking-opengl-version/14035/7 "2014-12-20T03:34:00Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 20, 2014, 11:26am UTC](https://forum.juce.com/t/checking-opengl-version/14035/8 "2014-12-20T11:26:40Z")

</div>

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&nbsp;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.

---

<div class="post-metadata">

**Author:** ![tayholliday](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/tayholliday/32/589_2.png) [@tayholliday](https://forum.juce.com/u/tayholliday)\
**Post date:** [December 22, 2014, 7:05pm UTC](https://forum.juce.com/t/checking-opengl-version/14035/9 "2014-12-22T19:05:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 23, 2014, 8:55am UTC](https://forum.juce.com/t/checking-opengl-version/14035/10 "2014-12-23T08:55:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Menno](https://forum.juce.com/u/Menno)\
**Post date:** [July 5, 2018, 12:51pm UTC](https://forum.juce.com/t/checking-opengl-version/14035/11 "2018-07-05T12:51:46Z")

</div>

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: [https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL\_ARB\_create\_context.txt](https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_create_context.txt)  
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?
