[英]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). 我正在运行Mac OSX Yosemite版本10.10和最新版本的SDL(2.0.3)。
I am trying to use at least OpenGL version 3+. 我试图至少使用OpenGL版本3+。 Without doing anything, my OpenGL version returns
2.1 INTEL-10.0.86
. 没有做任何事情,我的OpenGL版本返回
2.1 INTEL-10.0.86
。
The OpenGL commands work, but this is obviously not the version I need. OpenGL命令可以工作,但这显然不是我需要的版本。
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. 因此,在做了一些研究后,我发现在初始化SDL之后但在定义上下文之前
SDL_GL_SetAttribute(SDL_GLattr attr, int value)
使用SDL更改版本的方法是通过SDL_GL_SetAttribute(SDL_GLattr attr, int value)
函数。 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
. 使用此代码,OpenGL版本报告
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
. 这样可以正常工作,但我的OpenGL调用都不再有效,所以我在调用函数后检查了OpenGL错误并返回
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. 它提供相同的输出
4.1 INTEL-10.0.86
并返回相同的OpenGL错误(1282),并且没有任何OpenGL函数可以工作。
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
. 返回的新OpenGL版本为
null
但如果我将major_version更改为2并将minor_version更改为1,则返回到我的原始版本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. 在做了一些额外的研究之后,如果OpenGL在每次调用后都返回1282,那么上下文没有正确初始化。 This leads me to believe that this may be a bug with SDL not correctly creating the context?
这让我相信这可能是SDL无法正确创建上下文的错误? (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提交一个错误,看看是否有帮助。
SDL_GL_CONTEXT_PROFILE_CORE
... ...
...none of my OpenGL calls [ glMatrixMode, glLoadIdentity, glLoadIdentity, glBegin ] work anymore...
......我的OpenGL调用[ glMatrixMode,glLoadIdentity,glLoadIdentity,glBegin ]都不再工作了......
Those are all deprecated and will not work in a Core context. 这些都已弃用,不能在Core上下文中使用。
If you want to continue using a Core context you'll have to re-write your program to not use deprecated functionality. 如果要继续使用Core上下文,则必须重新编写程序以不使用已弃用的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.