View Full Version : glTexImage & .pgm
09-06-2008, 07:21 PM
Yes! I'm using a .pgm .ie, each 8 bit set contains a joint color value of RGB, so 255 = black and 0 = white.
Having trouble figuring out what Parameters I shud specify for glTextImage. in the format and internalformat fields
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, myTexture);
09-06-2008, 10:57 PM
Ok I have just specified GL_RED in the 3rd to last field. Seems to work. I also want to make all the white pixels i.e 0 in the pgm file, transperant, I have setup this:
Not sure how I set the alpha value to zero in the pgm for each pixel with a color of 0. Its kind of hard of course because each pixel has only an 8bit field.
09-07-2008, 07:16 AM
If I understand you well, you read a monochrome image and you want only shade of red. To gain alpha what I would do is to convert the the image R => RGBA.
If your image data have 4 pixels
0 => 0,0,0,0
100 => 100,0,0,255
125 => 125,0,0,255
200 => 200,0,0,255
You waste a little video memory but I think you can now use GL_DECAL for GL_TEXTURE_ENV_MODE.
hope it help.
09-07-2008, 03:33 PM
Hey thanks, I can't load the image using glTexImage as RGBA as it has a runtime error. I also want a shade of black not red.
Thanks for your help.
09-07-2008, 08:00 PM
Ok, my example is now
0 => 0,0,0,0
100 => 100,100,100,255
125 => 125,125,125,255
200 => 200,200,200,255
original size new size
4 bytes <=> 16 bytes
You have a runtime error because you still feed glTexImage2D with
the original array of pixel with GL_RGBA so a buffer overflow occur.
Look at my inner loop for reading a pgm file
//allocate image data for
//glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image_width,i mage_height,0,GL_RGBA,GL_UNSIGNED_BYTE,data); data = new unsigned char[image_width*image_height*4];//GL_RGBA format
unsigned char pgm_pixel_data;
for(i = 0 ,data_indice = 0 ; i < image_width*image_height ; i++)
if(pgm_pixel_data!=0)//pixel is opaque (grey scale)
data[data_indice++] = pgm_pixel_data; //R
data[data_indice++] = pgm_pixel_data; //G
data[data_indice++] = pgm_pixel_data; //B
data[data_indice++] = 255; //A
else//pixel is transparent
data[data_indice++] = 0; //R
data[data_indice++] = 0; //G
data[data_indice++] = 0; //B
data[data_indice++] = 0; //A
This work well. (no runtime error)
09-07-2008, 10:12 PM
hey, I implemented it at it worked beautifully. This is a real help to me as I am just coming to terms with all of the main features of open gl. so thanks ALOT for your time!!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.