SDL Can't load OpenGL Context over 2.1 Mac OSX Yosemite

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

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

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

So, after doing some research I found the way to change the version with SDL is through the SDL_GL_SetAttribute(SDL_GLattr attr, int value) function after you initialize 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 would work well but none of my OpenGL calls work anymore so I checked for an OpenGL error after a function is called and it 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 output 4.1 INTEL-10.0.86 and returns the same OpenGL error (1282) and none of the OpenGL functions work.

And my last attempt failed as well with a different outcome. Here was 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 returned is null but if I change the major_version to 2 and minor_version to 1 it returns to my original version 2.1 INTEL-10.0.86 .

Does anyone know a solution to this problem?

--Edit--

After doing some additional research, if OpenGL returns 1282 after every call the context is not initialized correctly. This leads me to believe that this may be a bug with SDL not correctly creating the context? (I honestly don't know that much so I'm going on a limb). I'll submit a bug to SDL and see if that helps anything.


SDL_GL_CONTEXT_PROFILE_CORE

...

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

Those are all deprecated and will not work in a Core context.

If you want to continue using a Core context you'll have to re-write your program to not use deprecated functionality.

链接地址: http://www.djcxy.com/p/38460.html

上一篇: 获取OpenGL / OpenCL共享上下文的HDC设备上下文

下一篇: SDL无法通过2.1 Mac OSX Yosemite加载OpenGL上下文