Search code examples
openglsdlsrgb

Can SDL create a sRGB OpenGL context?


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?


Solution

  • 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.