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

GLEW function bindings do not match OpenGL version?

Started by Althar Dec 23, 2014 at 11:21 PM 7 replies 4.9k views
Original Post
Althar
Althar

Hello all,

I am having a bit of an issue with my personal game engine, more specifically with GLFW's context & GLEW's initialisation.

I started off supporting the default context that my PC would support (OpenGL 4.4) but as I have now decided to make it cross-platform made the decision to settle for & comply with the specifications of OpenGL 3.3 (which is supported by my 2010 MacBook Pro).

I have managed to setup an OpenGL 3.3 context using GLFW' and the returned "GL_VERSION" is the expected value - on the other hand, it would appear that my GLEW is not properly initialised and will result in unhandled exceptions when trying to call certain functions.

For instance, my shader compilation code performs reflection to extract the vertex attribute name and bind them to pre-defined bindings :

  • OpenGL 4.4 : glGetProgramResourceName
  • OpenGL 3.3 : glGetActiveAttrib

For some reason obscure I am finding that the OpenGL 4.4 call works (glGetProgramResourceName) while the OpenGL 3.3 call (glGetActiveAttrib) results in a crash.

Any ideas what could be the cause of that and/or through what mechanic GLEW binds its functions?

Thanks in advance,

swiftcoder
swiftcoder

Did you remember to set glewExperimental to true before calling glewInit()?


   glewExperimental = GL_TRUE;
   glewInit();

It gets me every goddamn time I set up a new project.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Misantes
Misantes

Edit* Doh. swiftcoder beat me to the punch :P

I only have a loose understanding of how glew works, but I thought I'd throw this out there. Are you setting the glewExperimental global before initializing?

Also, you can check for support whether specific versions, extensions and such are supported. This page details a lot of it.


In general, you can check if GLEW_{extension_name} or GLEW_VERSION_{version} is true or false.
It is also possible to perform extension checks from string input. Starting from the 1.3.0 release, use glewIsSupported to check if the required core or extension functionality is available:
if (glewIsSupported("GL_VERSION_1_4  GL_ARB_point_sprite"))
{
  /* Great, we have OpenGL 1.4 + point sprites. */
}

Again, I only have a loose understanding of GLEW, but this is where I'd start. Hopefully it's of some help. If not, I'm certain someone will correct me shortly here smile.png

Beginner here <- please take any opinions with grain of salt
Althar
Althar
Thanks for the replies guys.

Although you both have a valid point, I am setting glew experimental. As far as I am aware I am doing the text-book initialisation sequence, namely :

- initialise GLFW
- set window hints (aka. request OpenGL3.3 explicitely)
- create the window and OpenGL context and set it as current
- initialise GLEW

I have run gDebugger to try and figure out what was going on. It would appear that GLFW first creates a 4.4 context, then destroys it and creates the requested 3.3 one. Just before initialising GLEW I query GL_VERSION and am positive it is using OpenGL3.3.

If I try and compile a shader with version >330 it will complain that it does not support it which is the expected behaviour.

What makes no sense is the fact that GLEW has its functions bound as if it was running 4.4. I doubt this would have any impact but It may be worth mentioning I am linking GLEW as a static lib (GLEW_STATIC with the single context variant).

The only explanation I can think of for the moment is that GLEW is somehow initialising against the initial context GLFW created (4.4) instead of the one I explicitly requested (3.3) which is the only one in existence at the time where glewInit is taking place.

I would happily cater for both implementations if I knew why GLEW behaved in such a way. In the meantime I am slightly concerned with the lack of consistency in behaviour and what I am observing. As it stand it would be impossible to implement my GL render interface following the OpenGL3.3 to the letter.
swiftcoder
swiftcoder




What makes no sense is the fact that GLEW has its functions bound as if it was running 4.4

Are you seeing this behaviour on the MacBook, or the Windows machine? And is this a core context, or a backwards-compatible context?

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Althar
Althar
Good point... The Macbook version seems fine as it is running a core profile, but now that you mention it I am not sure if this is the case for the Windows version.

I had a go at hinting GLFW to create a core profile on windows but didn't seem to make any difference. I'll have to revisit my test in gDebugger as it does sound quite likely.

I must admit I am still not on the ball with the concepts of core profile, forward and backward compatibility. I've come back to desktop GL after a few years of GLES1.0/2.0 and a lot of Direct3D.
Althar
Althar

On Windows, my OpenGL context is created as the following :

  • 3.3
  • Backwards-compatible
  • Debug context

I have also stepped through GLEW's initialisation process using gDebugger and the culprit function glGetActiveAttrib is being queried as expected - it would just appear that it is either or becomes invalid later down the line.

I have noticed however that the "Renderer version" comes out as 4.4 instead of 3.3 although I am not sure if this can be changed or whether this is at the driver level.

Althar
Althar

Just a quick progress report : I thought I would ditch GLEW (which apparently has a few issues with core profiles) and tried my luck with GL3W instead.

Verdict, the result is exactly the same - for some reason, a call to gl3wIsSupported(3, 3) fails even though the running context is OpenGL 3.3 and my PC has full core support for it. I can call the same function with different versions (tried 2.1, 3.0 & 4.4) and all of them work just fine...

What I do not understand is that I should be able to run my code in two different ways :

  • Running an OpenGL 4.4 context with backwards compatibility
  • Running an OpenGL 3.3 core context

But for some reason none of these two options work...

Althar
Althar

Ok... I finally managed to get to the bottom of it.

I was misreading gl3wIsSupported return value, as a result of my confusion and it was working as expected after all.

The issue in the end was that I was providing invalid parameters to my glGetActiveAttrib call - specifically the size and type parameters are non-optional (I was passing NULL, silly me...) which didn't seem to bother the Mac's implementation but on the PC would result in a horrible crash.

Anyway, thanks guys for your help

Topic Locked

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

Sign in to reply to this topic.