Question

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?

Was it helpful?

Solution 3

The "usual workaround" is "don't use SDL." If your tool doesn't support it, your tool doesn't support it, and that's that.

Your suggested workaround to render to an internal sRGB image is... not as useful as you think.

Will it work? Yes, in the sense that you will get images who's colors are properly gamma correct (though not because of enabling or disabling GL_FRAMEBUFFER_SRGB). However, you will get some degrading of image quality, because the non-linear 24-bit sRGB colorspace does not convert well to a linear 24-bit linearRGB colorspace. You'll lose some color definition.

The point of being able to present an sRGB image directly is to avoid that conversion and the resulting loss of color definition.

Whether you can live with those artifacts is up to you. I'd just as soon avoid using SDL, or hacking SDL to let you do what you need to.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top