# OpenGL textures look poor

I'm having some issues loading in textures in OpenGL, as my textures keep rendering incorrectly or coming out looking muddy. For instance, here I tried to load a 256x256 color spectrum image. On the left is how it looks in OpenGL and on the right is how it looks in an image viewing program: As you can see, while the left image resembles the right image, the left image appears to squish the blues, and greens, and extend the pinks.

I also tried loading in this 512x512 image of a dog and the result came out like this (again, left is OpenGL, right is image viewer): For this image, the image looks like it has lost a lot of its color, resulting in something that looks white washed and like it came out of a 1970s camera. (the fact that is flipped is fine however since the cube that I am drawing this on has some texture coordinates flipped to accommodate for a different image).

I load in these .BMP textures using SOIL, as such: glEnable(GL_TEXTURE_2D);

GLuint texID = 0;
glGenTextures(1, &texID);

int height = 0, width = 0;

glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, imgData);
// set texture filtering, gen mip map


Then in my fragment shader I do the following to apply the texture:

#version 330 core
in vec2 TexCoord;

uniform sampler2D textureSampler;

void main() {
gl_FragColor = texture2D(textureSampler, TexCoord);
}

• Is gamma correction applied? – Ocelot Oct 19 '16 at 15:53
• @Ocelot Yes, I used glEnable(GL_FRAMEBUFFER_SRGB) to enable OpenGL's gamma correction. – user3250889 Oct 19 '16 at 15:56
• Have you also enabled sRGB reads from your texture/sampling state? You might accidentally be mixing linear and gamma corrected colours. – DMGregory Oct 19 '16 at 16:10
• @DMGregory I don't think so, I'm not really sure what you mean, though... How would I enable sRGB reading from the texture? – user3250889 Oct 19 '16 at 16:15
• I'm not fluent in OpenGL, but quoting this GPU Gems article, "Passing GL_SRGB_EXT instead of GL_RGB to glTexImage2D, for example, ensures that any shader accesses to the specified texture return linear pixel values." Check if that works for you, and we can write it up as an answer if that turned out to be the culprit. – DMGregory Oct 19 '16 at 16:55

This has been solved in the comments, but for everyone comming here: I had the same problem that textures appeared washed out on certain (Intel?) GPUs. It turned out that OpenGL had enabled GL_FRAMEBUFFER_SRGB by default on some hardware. Calling glDisable(GL_FRAMEBUFFER_SRGB) right after context creation fixed it for me.