Handmade Hero»Forums»Code
Jackson
6 posts
Noticeable difference in texture under GL_SRGB8_ALPHA8 - why?
Hi All,

Working my way through the OpenGL init portion of the episodes and could use some help understanding some colour space intriacies.

Essentially when I set the expected texture format to GL_SRGB8_ALPHA8 my textures appear differently and I don't understand why.

Here is my current understanding of things:

- The texture (standard .bmp file) was created in sRGB colour space with GIMP
- The texture is opaque, so there shouldn't be any gamma correction or blending noise affecting the result
- Static monitor display profile

When I pass GL_SRGB8_ALPHA8 the textures are noticeably darker compared to GIMP and the software renderer. When I pass GL_RGBA8, the display matches GIMP and the software renderer.

So what's happening here? OpenGL is modifying the display profile for its window / context only and thus the difference? Or perhaps I am misunderstanding something more fundamental or have something initialised incorrectly?

Thanks
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Noticeable difference in texture under GL_SRGB8_ALPHA8 - why?
In order for sRGB to work correctly it needs to be applied correctly through the entire pipeline. Setting the texture up properly is only the first step. If you enable sRGB textures, it means your color values will all be turned into linear color during texture sampling - but then what do you do with those samples? If you are just writing them directly to a color buffer, but that color buffer itself isn't set up to do a reverse mapping back to sRGB, then if it is displayed it will be incorrect (since it's colors are linear but the display assumes it is gamma-corrected).

- Casey
Jackson
6 posts
Noticeable difference in texture under GL_SRGB8_ALPHA8 - why?
Thanks Casey. What was confusing me was that I wasn't doing anything special with the samples.

However, I have subsequently stumbled upon the solution. It appears as if it was Intel graphic driver related as trying it out on a machine with an nVidia card and all is gravy. At least one other has had similar experiences on the Interwebz as well - http://stackoverflow.com/question...-call-glenablegl-framebuffer-srgb