Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can SDL create a sRGB OpenGL context?

Tags:

opengl

sdl

srgb

The documentation of SDL does not seem to mention much about color spaces. I don't see any SRGB flag/parameter for SDL_SetVideoMode or SDL_GL_SetAttribute. Is it possible at all for SDL to ask OpenGL to perform the color correction when writing on the FrameBuffer 0? GLUT seems to be able to provide that functionality.

If SDL cannot do it, what is the usual workaround? I am considering rendering to a sRGB texture with GL_FRAMEBUFFER_SRGB enabled, and then rendering that into the FrameBuffer 0 with FRAMEBUFFER_SRGB disabled. Any better idea?

like image 466
Niriel Avatar asked Dec 01 '22 03:12

Niriel


2 Answers

Sorry to revive an old question here, but I wanted to note that SDL 2.0.1 will explicitly let you request an sRGB context:

SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
// etc.
SDL_Window *win = SDL_CreateWindow(...);
SDL_GL_CreateContext(win);

This works on Windows and X11 (Mac OS X, etc, doesn't offer this functionality at the moment). It's worth noting that, before SDL 2.0.1 offered this, most GL contexts on modern hardware are already sRGB capable by default. But there you go.

like image 148
Ryan C. Gordon Avatar answered Dec 10 '22 03:12

Ryan C. Gordon


To be slightly more precise: You just need to call glEnable(GL_FRAMEBUFFER_SRGB) to make Framebuffer 0 into an SRGB framebuffer.

If you are on SDL2, you should request the capability by calling SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1) during init, but if you are on an earlier version of SDL, it seems that right now graphics drivers do not care if you request it beforehand.

like image 37
mtb Avatar answered Dec 10 '22 03:12

mtb