Missing GL version

I am completely new to glew, opengl, etc. Recently I encounter a problem where an error message shows 'Missing GL version'

The code where error is thrown
1
2
3
4
5
6
7
8
9
10
11
        ...
        Window* window = new Window();
 
        GLenum err = glewInit();
        if (err != GLEW_OK)
        {
                std::cout << "Glew Error: " << glewGetErrorString(err) << std::endl;
                return -1;
        }
        ...
 

After searching on the internet, it looks like glcontext is not created appropriately.


But within window variable, it has
1
2
3
4
5
6
7
8
9
10
11
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
 
        _window = SDL_CreateWindow("My Game Window",
                0,
                0,
                1024, 768,
                SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
 
        _glcontext = SDL_GL_CreateContext(_window);
 

Others (http://stackoverflow.com/questions/13826150/sdl2-opengl3-how-to-initialize-sdl-inside-a-function) mentions the reference problem. I then tried copying the above code snippet to replace the line
1
2
        Window* window = new Window();
 

So the code looks like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int main(int argc, char *argv[])
{
        SDL_Window* _window;
        SDL_GLContext _glcontext
 
        SDL_Init(SDL_INIT_EVERYTHING);;
 
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
 
        _window = SDL_CreateWindow("My Game Window",
                0,
                0,
                1024, 768,
                SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
 
        _glcontext = SDL_GL_CreateContext(_window);
 
        GLenum err = glewInit();
        if (err != GLEW_OK)
        {
                std::cout << "Glew Error: -> " << glewGetErrorString(err) << std::endl;
                return -1;
        }
        ...
}
 

However, it still throws 'Missing GL version'

Any place I may miss? What might cause such error and how to fix it?

I appreciate any suggestion.
It seems that calling SDL_GL_* functions before context creation can mess things up (which makes sense if you think about it). I get the same error as you if I run your code.

However, if I move the SDL_GL_* calls after the context creation, I don't get any errors from glewInit().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <SDL2/SDL.h>
#include <GL/glew.h>

#include <iostream>

int main(int argc, char *argv[])
{
        SDL_Window* _window;
        SDL_GLContext _glcontext;
 
        SDL_Init(SDL_INIT_EVERYTHING);;
 
        _window = SDL_CreateWindow("My Game Window",
                0,
                0,
                1024, 768,
                SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
 
        _glcontext = SDL_GL_CreateContext(_window);
        
        // Now that the context is created, we can call our SDL_GL_ functions
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
 
        GLenum err = glewInit();
        
        if (err != GLEW_OK)
        {
                std::cout << "Glew Error: -> " << glewGetErrorString(err) << std::endl;
                return -1;
        }
        
        SDL_Quit();
}


It might be an even better idea to fiddle with the context after glewInit(), so glewInit() has a clean context to work with, but I don't know anything about how glewInit() works.
Last edited on
Thanks for the advice. It helps me find out the cause. I google again and notice that, although the flow is correct with following order
1
2
3
4
5
SDL_GL_SetAttribute()
...
SDL_CreateWindow()
...
SDL_GL_CreateContext()


stated at http://wiki.libsdl.org/SDL_GL_SetAttribute

The SDL_GL_DEPTH_SIZE in the example described is 16, instead of the 32 in the source that doesn't work.
 
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);


Changing SDL_GL_DEPTH_SIZE value from 32 to 16 or 24 gets rid of 'Missing GL version' error message.

Thanks again for your help! That's very useful.
closed account (S6k9GNh0)
shogun1234, that's odd... that's not included in any of my examples. The DEPTH_SIZE also shouldn't affect OpenGL initialization from GLEW... Just remove that line and a sane default will be chosen, especially if you don't know what that is or don't use it.

Anyways, I would suggest setting the variable "glewExperimental" to "true". You also need to set the OpenGL version wanted.

1
2
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);


Or else you'll get a rather old compatibility version, regardless of platform or headers used. You should set attributes before creating a context or window!

Remember that SDL is a C library. In this case, none of its structures have constructors so using something like "new" on them is really, really bad and asking for a memory leak somewhere. You must use their facilities to initialize and close out a structure!
Last edited on
Topic archived. No new replies allowed.