View Full Version : [SOLVED]- Uploading a grayscale image to OpenGL

02-09-2011, 12:03 AM
Hi all,
I m using opengl3.3 core profile. Previously for loading an 8bit image, I would simply call

glTexImage2D(GL_TEXTURE_2D,0,GL_INTENSITY,w,h,0,GL _LUMINANCE, GL_UNSIGNED_BYTE, pData) and it worked out fine.

I just see the latest specs and both GL_INTENSITY and GL_LUMINANCE are deprecated and thus the error bit is set in the forward compatible context. My question is what is the replacement of these? I can put my data in red/green/blue channel using GL_[RED,GREEN,BLUE] format but it comes out in colors (red/green/blue resp.). Do i need to explicity generate the other two components also with the same value and pass it using GL_RGB? or is there another alternate which accepts the single intensity value so that i dont have to replicate the two channels needlessly?

02-09-2011, 12:17 AM
Nevermind I got it. I can use a single channel (GL_RED for instance to pass the data to this channel only) and in shader assign it to the remaining channels like this.

vFragColor.rgb = texture(textureMap,uv).rrr;

Leith Bade
02-09-2011, 04:06 PM
Reference for people reading this:

Also allows the equivalent behaviour of GL_INTENSITY and GL_LUMINANCE without adding extra code to the shader.

It also allows the texture fetch hardware to do the swizzle rather than adding extra operations to the compiled shader.