Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: OpenGL TGA loading

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2005
    Posts
    3

    OpenGL TGA loading

    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?

  2. #2
    Intern Contributor
    Join Date
    Apr 2002
    Location
    Spain
    Posts
    63

    Re: OpenGL TGA loading

    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:

    Code :
    	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_FILTER,GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     
    	glEnable(GL_TEXTURE_2D);
    	glAlphaFunc(GL_GREATER,0); //Discard pixels with alpha==0
    	glEnable(GL_ALPHA_TEST);

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2005
    Posts
    3

    Re: OpenGL TGA loading

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •