PDA

View Full Version : OpenGL TGA loading



McTuble
11-08-2005, 07:45 PM
I've been having some real problems lately. I'm working on a chess program and want the pieces to be texture mapped with nice images rather then plain primitives. So the problem is I was able to get it to load BMP's however is there a way to get it to not display a certain color? I figured it'd be best to go with TGAs. Another question....Is it true that TGAs only suuport transparency at 32bpp? So basically I'm looking for the best way / easiest way to display images of the pieces along with the transparency. So I believe I loaded a TGA file before at least it said everything went ok but when I go to draw it on top of the square where it should be it is just white. So many problems here. Sorry would some of my source code help here? Any thoughts?

Azdo
11-09-2005, 01:55 AM
In addition to the R,G,B color planes of the TGA file, there's channel called 'alpha' which states the translucency of every of these pixels. You must also load them using the RGBA format and set the blending GL function if you want to 'mix' colors or set the alpha function if you want instead only to discard some pixels. Here's an example:


glBindTexture(GL_TEXTURE_2D,1);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA, //The file has alpha information
tex->w,
tex->h,
0,
GL_RGBA, // The texture will store also that alpha information per pixel
GL_UNSIGNED_BYTE,
tex->pixels);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER,0); //Discard pixels with alpha==0
glEnable(GL_ALPHA_TEST);

McTuble
11-09-2005, 05:48 AM
OK, I'm not really sure how but I was able to get a little demo going and it loads and displays TGA files correctly. Thanks for replying....it helped.