CreateRenderer downgrades the OpenGL context, can it be prevented?

I am on Mac OS (10.9.3). I can create a window + context which is a 3.3 Context as requested. But once I create the renderer SDL tells me that the renderer is invalid. Apart from that I can use the renderer to draw and copy textures. But creating the renderer also seems to change the OpenGL context to a 2.1 profile :(

Is there a way to prevent that?

[EDIT]

SDL2 and glew are linked as a static library. glewExperimental is not set to GL_TRUE.

C++ source:

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()

Output:

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

The error you are getting could be a bug, specially if the Renderer ends up working fine despite reporting "Invalid renderer".

The problem you have with SDL lowering the context version is due to the fact that the renderer is implemented with OpenGL 2.1 calls, so it needs to create a 2.1 GL context.

You could try creating the renderer first, and then set SDL_GL_CONTEXT_MAJOR_VERSION, etc to create a 3.3 context.

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

上一篇: SDL重置glViewport

下一篇: CreateRenderer降级OpenGL上下文,是否可以防止?