View Full Version : how to show the grey-scale image?
sorry for this stupid queation. I just used the function glTexImage2D to show an image:
glTexImage2D(GL_TEXTURE_2D, 0, 3, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
It works well with a color image, but when I tried with an intensity(grey-scale) image and changed the components(the 2rd parameter of this function) to 1, just a white block of same size appears on the window. Can anybody give me some suggestion?
sorry, wrong type, should be the 3rd, not 2rd.
first of all ( im still working on enlighten all people http://www.opengl.org/discussion_boards/ubb/smile.gif ) the 3rd parameter shoulndt have just '3', it should have an enumrator telling the driver what internal format you want ( GL_RGB(A)4 for 16bit, GL_RGB(A)8 for 24/32 bit, or just GL_RGB(A) if you dont care.
for the rest of the question, format should be GL_LUMINANCE, and internalfomrat (3rd parameter) should be one of GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8, depending on selected quality
Thank you for your reply.
Do you mean like this:
glTexImage2D(GL_TEXTURE_2D, 0, 3, image->sizeX, image->sizeY, 0, GL_LUMINANCE, GL_INTENSITY, image->data);
But it doesn't work.
you sttill use bytes dont you?
and what did i say about the 3rd parameter (grrr)!!
glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, image->sizeX, image->sizeY, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image->data);
I'm sorry for misunderstanding. But it still doesn't work.
do you get any errors ? ( glGetError )
If you still use your colored (that means 3 channel RGB texture) but want OpenGL to make a greyscale texture out of it, then you have to do it this way:
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, image->sizeX, image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
The 7th parameter tells OpenGL how YOU have the data at hand (in this case you have a 3 component image, consisting of red, green and blue) and the 3rd parameter tells OpenGL how IT is supposed to store it (int this case as a greyscale texture).
Mazy has mixed the 3rd and 7th parameter accidantly around.
You should get a good book or some other documentation about OpenGL. Such problems can easily be solved by simply looking up a description of the function.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.