SDL Cannot Load OpenGL Context over 2.1 Mac OSX Yosemite

I am running Mac OSX Yosemite version 10.10 and the latest SDL (2.0.3).

I am trying to use at least OpenGL version 3+. Without doing anything, my version of OpenGL returns 2.1 INTEL-10.0.86

.

The OpenGL commands work, but this is obviously not the version I want.

So, after some research, I found a way to change the version using SDL via a function SDL_GL_SetAttribute(SDL_GLattr attr, int value)

after initializing the SDL, but before you define the context. So here is my code:

if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
    printf("Failed to initialize SDL. Error (SDL): %s.\n", SDL_GetError());
    return false;
}

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); //I read somewhere that this may help

window = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, (SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN));

if (!window)
{
    printf("Failed to create the window. Error (SDL): %s.\n", SDL_GetError());
    return false;
}

context = SDL_GL_CreateContext(window);

      

Using this code, the OpenGL version reports 4.1 INTEL-10.0.86

. This will work well, but none of my OpenGL calls are working anymore, so I checked the OpenGL error after the function call and returns 1282

.

The strange thing is that when I change the code to this

...
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
//SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); //I read somewhere that this may help
...

      

It gives the same result 4.1 INTEL-10.0.86

and returns the same OpenGL error (1282) and none of the OpenGL features work.

And my last attempt failed with a different result. Here is my code:

...
//SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); //I read somewhere that this may help
...

      

The new OpenGL version comes back null

, but if I change major_version to 2 and minor_version to 1, it reverts back to the original version 2.1 INTEL-10.0.86

.

Does anyone know a solution to this problem?

- Edit -

After doing some more research, if OpenGL returns 1282 after each call, the context is not initializing correctly. Does this make me think it might be a bug with SDL not creating context correctly? (Honestly, I don't know, so I'm walking on limbs). I'll post a bug to SDL and see if that helps anything.

+3


source to share


1 answer


SDL_GL_CONTEXT_PROFILE_CORE

...

... none of my OpenGL calls [ glMatrixMode, glLoadIdentity, glLoadIdentity, glBegin ] work anymore ...



They are all deprecated and will not work in the main context.

If you want to continue using the main context, you will have to rewrite your program to avoid using deprecated functions.

+3


source







All Articles