我使用SDL2为OpenGL设置了以下(工作)设置代码:
int main(int argc, char* argv[])
{
SDL_SetMainReady();
if (SDL_Init(SDL_INIT_VIDEO) != 0) return 1);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
auto sdl_window = SDL_CreateWindow("GL Experiment",
SDL_WINDOWPOS_CENTERED, // x position.
SDL_WINDOWPOS_CENTERED, // y position.
640, // Width.
640, // Height.
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
if (sdl_window == nullptr) return 2;
auto sdl_gl_context = SDL_GL_CreateContext(sdl_window);
if (sdl_gl_context == nullptr) return 3;
...
但是,如果我将SDL_GL_CONTEXT_VERSION...
行更改为:
// Use a core profile setup.
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);
然后它以奇怪的方式打破:
glClear
似乎仍然有效(窗口中选择了任何背景颜色)。上下文报告的属性有一些奇怪之处:</ p>
SDL_GL_RED_SIZE: 0
SDL_GL_GREEN_SIZE: 0
SDL_GL_BLUE_SIZE: 0
SDL_GL_ALPHA_SIZE: 0
SDL_GL_BUFFER_SIZE: 4
SDL_GL_DOUBLEBUFFER: 1
SDL_GL_DEPTH_SIZE: 0
SDL_GL_STENCIL_SIZE: 0
SDL_GL_ACCUM_RED_SIZE: 0
SDL_GL_ACCUM_GREEN_SIZE: 0
SDL_GL_ACCUM_BLUE_SIZE: 0
SDL_GL_ACCUM_ALPHA_SIZE: 0
SDL_GL_STEREO: 0
SDL_GL_MULTISAMPLEBUFFERS: 0
SDL_GL_MULTISAMPLESAMPLES: 0
SDL_GL_ACCELERATED_VISUAL: 1
SDL_GL_CONTEXT_MAJOR_VERSION: 3
SDL_GL_CONTEXT_MINOR_VERSION: 3
SDL_GL_CONTEXT_FLAGS: 2
SDL_GL_CONTEXT_PROFILE_MASK: 1
SDL_GL_SHARE_WITH_CURRENT_CONTEXT: 0
SDL_GL_FRAMEBUFFER_SRGB_CAPABLE: 0
因此上下文声称具有0位颜色位深度等。这似乎与初始glClear
调用的呈现不一致,但它很乐意呈现颜色。
我检查了一些OpenGL函数,它们似乎解析为实际的函数地址(只是使用OSX的<opengl/gl3.h>
来获取这些函数,但我已经检查过,它们与加载函数指针的地址相同通过SDL收益率。
更新
glGetString的输出是:
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: NVIDIA GeForce GT 750M OpenGL Engine
GL_VERSION: 4.1 NVIDIA-10.6.47 310.42.05f01
GL_SHADING_LANGUAGE_VERSION: 4.10
这是在请求3.3 / Core时,所以很明显它给出了4.1上下文。当请求2.1时,它是相同的,但正确显示GL_VERSION: 2.1 ...
。
答案 0 :(得分:0)
事实证明,OpenGL上下文已经成功创建,即上面的代码在创建上下文方面效果很好。
因此,这个问题似乎有两个方面:
<强>更新强>
花了一些时间在前面的章节中使用3.3 Core上下文获取OpenGl SuperBible示例,我在后面的章节中发现他们故意针对兼容性配置文件,因此本书将适用于早期的系统。这解释了上面的第1点,遗憾的是,在描述如何开始时,他们没有预先提供这些信息!