我在Mac OS(10.9.3)上。我可以根据请求创建一个3.3上下文的窗口+上下文。但是一旦我创建渲染器,SDL就会告诉我渲染器无效。除此之外,我可以使用渲染器绘制和复制纹理。但是创建渲染器似乎也将OpenGL上下文更改为2.1配置文件:(
有没有办法防止这种情况?
[编辑]
SDL2和glew作为静态库链接。 glewExperimental未设置为GL_TRUE。
C ++来源:
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_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
h_main_window = SDL_CreateWindow(
title.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
width,
height,
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN
)
SDL_GL_CreateContext(h_main_window)
glewInit()
std::cout << "gl_renderer:" << glGetString(GL_RENDERER) << std::endl;
std::cout << "gl_context: " << glGetString(GL_VERSION) << std::endl;
std::cout << "gl_shading_lang_version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
SDL_CreateRenderer(
h_main_window,
-1,
SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE
)
std::cout << "gl_renderer:" << glGetString(GL_RENDERER) << std::endl;
std::cout << "gl_context: " << glGetString(GL_VERSION) << std::endl;
std::cout << "gl_shading_lang_version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
initShaders()
输出:
gl_renderer:Intel HD Graphics 3000 OpenGL Engine
gl_context: 3.3 INTEL-8.24.13
gl_shading_lang_version: 3.30
SDL Error: Invalid renderer
gl_renderer:Intel HD Graphics 3000 OpenGL Engine
gl_context: 2.1 INTEL-8.24.13
gl_shading_lang_version: 1.20
Compile failure in vertex shader:
ERROR: 0:1: '' : version '330' is not supported
ERROR: 0:3: 'layout' : syntax error syntax error
Compile failure in fragment shader:
ERROR: 0:1: '' : version '330' is not supported
Linker failure: ERROR: One or more attached shaders not successfully compiled
答案 0 :(得分:0)
您获得的错误可能是一个错误,特别是如果渲染器尽管报告“无效的渲染器”仍然工作正常。
SDL降低上下文版本的问题是由于渲染器是使用OpenGL 2.1调用实现的,因此需要创建2.1 GL上下文。
您可以先尝试创建渲染器,然后设置SDL_GL_CONTEXT_MAJOR_VERSION等以创建3.3上下文。