0
votes

I have tried setting the OpenGL context to v3.3 using the following code, it creates a 4.1 context.

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);

Am I doing something wrong or is it a mac problem?

1
You don't need SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG, that is an obsolete flag used for OpenGL 3.0 and 3.1 only, it is irrelevant in 3.2 and onwards, and it didn't exist prior to 3.0.Dietrich Epp
Also note that GLEW has some pretty bad issues with core contexts, but it's also not necessary to use GLEW on OS X because OS X uses weak linking—you can just #include <OpenGL/gl3.h>, and any functions which aren't supported will just be NULL at runtime, just as if you had used GLEW. GLEW is unable to check for the presence of extensions in core contexts, so there is no point to using it on OS X unless it happens to make your cross-platform life easier.Dietrich Epp

1 Answers

2
votes

OpenGL does not provide any guarantees that when you ask for an OpenGL X.Y context, that you get exactly an OpenGL X.Y context. It depends on the drivers you use.

  • On OS X, if you ask for a core context, you get the highest version supported on your hardware and operating system combination. If you ask for a compatibility context, you get 2.1.

  • On my Linux/Mesa system, I always get 3.0 compatibility contexts, and 3.3 core contexts.

  • On my Windows/AMD system, I get the exactly the version I ask for.

The 4.1 context should work fine for you if your code assumes that the context is 3.3. Just check that the GL version is >= the version you need, and check that you have a compatibility context if you need it.