PDA

View Full Version : Setting up sRGB



BBeck1
10-31-2016, 05:24 AM
I just learned that sRGB is a thing in the past couple of weeks, and mostly learned what it is this morning. That said, I'm trying to figure out how to get my OGL program to be using sRGB.

I'm using GLFW and FreeImage.

I initialize GLFW with "glfwWindowHint(GL_FRAMEBUFFER_SRGB_EXT, GL_TRUE);". And I'm creating my texture with "glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8_EXT, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)Texture);".

Is that all there is to implementing sRGB? Do I need anything in addition to that? If the image is encoded in another color space, will it automatically convert it?

The only place where FreeImage seems to affect any of this is that when I load the image I call "ImageBitMap = FreeImage_ConvertTo32Bits(ImageBitMap);".

john_connor
10-31-2016, 06:14 AM
Is that all there is to implementing sRGB?

i think you have to call also:

glEnable(GL_FRAMEBUFFER_SRGB);

https://www.opengl.org/wiki/Framebuffer#Colorspace

GClements
10-31-2016, 09:09 AM
I initialize GLFW with "glfwWindowHint(GL_FRAMEBUFFER_SRGB_EXT, GL_TRUE);"
According to the GLFW documentation, that isn't a valid hint.

AFAICT, you should be using glfwWindowHint(GLFW_SRGB_CAPABLE, 1) to select an sRGB-capable visual. Then you can use glEnable(GL_FRAMEBUFFER_SRGB_EXT) to make the implementation perform the linear-to-sRGB conversion when rendering to the window.

Also, note that there are differences between EXT_framebuffer_sRGB and OpenGL 3.0. E.g. the extension uses glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT) to determine whether the current framebuffer is sRGB-encoded, while 3.0 uses glGetFramebufferParameteriv(GL_FRAMEBUFFER_ATTACHM ENT_COLOR_ENCODING) to query whether a specific colour attachment is sRGB-encoded.

Also, the OpenGL specification only says that "For the default framebuffer,
color encoding is determined by the implementation" (9.2.3), as that aspect is up to the window system (wgl/glX/etc), which is outside the scope of the specification.

BBeck1
11-02-2016, 02:17 AM
Thanks guys! Looks like I've got it working now.