OpenGL 3 context on Windows?

Hi!

My SDL app uses OpenGL 3, and while the code works perfectly on macOS, on Windows (tested Windows 7) SDL create an OpenGL 1.1.0 context (as reported by glGetString(GL_VERSION)).

My code is quite simple:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

window = SDL_CreateWindow("App", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                          320, 240, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);

SDL_GLContext gl_context = SDL_GL_CreateContext(window);
printf("%s\n", glGetString(GL_VERSION));

Using lower minor numbers for the version did not help (I still get 1.1.0). Any help?

1 Like

It may not be able to run OpenGL 3, but I would doubt that. If it can run windows 7, it’s probably more than capable of doing better than OpenGL 1.1. Can you make sure that it isn’t caused by hardware? How old is the computer?

EDIT: I think it might be caused by requesting the version before creating the context.

It’s a VM running in VMware Fusion on a late 2014 iMac. So the SDL_GL_SetAttribute should come after SDL_GL_CreateContext? I’ll try that and see if it helps.

I would think so, but that’s just a guess.

EDIT: changed this to a comment

Didn’t work. Additionally, it broke the Mac port.

What do you mean it “broke it”?

It’s as-if I didn’t request an OpenGL version at all – it falls back to a default of OpenGL 2.1.

Do you know if you have the right drivers?

The context version and other attributes need to be set before creating the context – your original code was correct.

VMs are unlikely to support OpenGL 3, you should try with an actual windows system.

1 Like

Sorry about that, that would have been my next guess.

Duh, apparently I forgot turning on GPU acceleration on VMWare so it supported only 1.1.0, but even after enabling it it supported only 2.1. In any case, it’s a setup issue. Thanks!

Edit: Seems that Parallels does support OpenGL up to version 3.2 on Windows guests. Seems useful! :slight_smile: