Transparent texture color

Moderator
Posts: 133
Joined: 2008.05
Post: #1
Code:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0);



Is supposedly the code that will "make sure the transparent part of the texture isn't drawn", according to this book I'm reading. What color in the texture image file will be treated as transparent though?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
No color. The alpha channel is used to determine transparency.
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #3
Ok. So I assume I would have to save and load my texture as a targa or some such thing in RGBA format, instead of using pict like I am now? And in photoshop or whatever, I just make sure that whatever parts of my texture that I want to be transparent are alpha of 1?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Quote:Originally posted by LongJumper
Ok. So I assume I would have to save and load my texture as a targa or some such thing in RGBA format, instead of using pict like I am now? And in photoshop or whatever, I just make sure that whatever parts of my texture that I want to be transparent are alpha of 1?


0 alpha is transparent, 1 (255) alpha is opaque. But yes, that's the theory.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #5
Check out the link from this thread:

http://www.idevgames.com/forum/showthrea...eadid=5236

If you press any key from 1 to 9, and q to p, the app will blend the RGBA texture from a TGA file with different settings.
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #6
So I made a targa file in GraphicConverter, added an alpha mask where the part I want drawn is black(0 alpha) and the other part is white(255, 1?). I don't know to reverse them or not, but either way my code isn't blocking out any of it.

What I want to do is have a obviously square texture drawn into a quad, but only this little circle in the middle showing(the button).

I'm pretty sure the image file(aside from the reversal or the alpha channel values) is set up fine, it loads up as a GL_RGBA and I create the texture that way.

What are appropriate values to send ot glBlendFunc and glAlphaFunc to get this working?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
The code you posted originally looks good.
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #8
Must not have drawn it right then. It just displays the whole thing.

I don't know if you have any experience with GraphicConverter(Everyone here seems to though). I just Add Alpha Mask/Channel, then I do a Show Alpha Channel, and then I draw a black dot in the center, save it as a TGA. Doesn't seem to be saving the alpha channel maybe? I dunna. I have to be missing something somewhere, because it doesn't work Smile

edit: acutally, no matter what I do to the image file nothing changes.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.11
Post: #9
Check out this source code:

http://home.earthlink.net/~yexirocks/MyGameSource.dmg

It can load an image from a JPG, PNG, or TGA file, and then display all the possible OpenGL blend combinations.

You may use the TGA that comes with it just to check if your code is working right.
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #10
Thanks for all the help. Using that other image really narrowed down where my problem was...it was when I load the texture, for some reason I had a 3 in my internalFormat variable passed to gluBuildMipmaps... that was so annoying Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Preventing texture from creating transparent gaps on edges ardowz 3 1,189 Jan 21, 2014 11:28 AM
Last Post: SethWillits
  ? Find color value of 'pixel' in color buffer? Elphaba 1 4,385 Jul 22, 2009 01:23 PM
Last Post: Bachus
  Transparent textures kordeul 2 2,551 Aug 27, 2007 01:38 AM
Last Post: kordeul
  Texture Color is wrong DesertPenguin 7 3,976 Feb 14, 2006 09:04 PM
Last Post: DesertPenguin
  Transparent Color? Josh 6 5,747 Apr 22, 2002 05:27 AM
Last Post: Josh