OpenGL 3.x context creation using SDL2 on OSX (Macbook Air 2012)

Captain Head picture Captain Head · Aug 14, 2012 · Viewed 10.1k times · Source

As far as I'm aware, the Macbook Air 2012 supports OpenGL 3.2. When using SDL 2.0 to create the OpenGL context, however, the context is only opengl version 2.1.

Is it possible for SDL 2.0 to create a GL 3.2 context?

Answer

David Greiner picture David Greiner · Oct 27, 2012

For everyone who still has this problem as of Wednesday, Oct 10th, SDL2 allows you to create an OpenGL 3.2 context on Macs running Mac OS X 10.7 (Lion) and up. You just need to add this code:

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);

If you're running OS X 10.10, or the solution above still does not resolve the problem, changing the second line of the above example from

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

to

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

may work for you.