Masking question (from OpenGL newbie)

Started by
13 comments, last by Irrelevant 22 years, 2 months ago
What''s the simplest/most efficient way to set OpenGL to read black pixels (RGB 0,0,0) as transparent? I was playing around with glBlendFunc() but couldn''t get anything to work. I''m using 24-bit bitmaps in my images. Thanks for any help/suggestions
Advertisement
You could use additive blending (be warned, you won''t get exactly what you''re expecting though). My advice is to simply use an alpha channel with alpha testing though. Not only is it faster, it could get you the exact kind of transparency you''re looking for.

thanks for the advice. however, does this mean I can''t use bitmaps anymore? I was under the impression that bitmaps didn''t support alpha channels. If that is the case, I had better get writing my targa file loader
No, bitmaps don''t support alpha channels. Targa''s are pretty easy to load (even the compressed ones are ), so you shouldn''t have a problem with them.

well, since you''ve been so helpful so far
how do i go about using alpha channels to do transparency?

thanks again for your time
If you wanted to make all pixels with an alpha value of 0 transparent, you'd do the following:
  glEnable(GL_ALPHA_TEST);  glAlphaFunc(GL_GREATER, 0);  
The second line causes only pixels with an alpha value greater than zero to be drawn. Look at the documentation for glAlphaFunc for the other options available to you.
Also, when you create your texture image, it must be 32 bit. Make sure it has an alpah channel where all the pixels you want to be transparent are black, and all those that you want to see are white

'I sure could use a vacation from this bullshit three ring circus sideshow of freaks...' - TOOL
[TheBlackJester]


Edited by - TheBlackJester on February 16, 2002 1:15:35 PM

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan Name: [email=darkswordtbj@hotmail.com]TheBlackJester[/email]Team: Wildfire Games
Projects O A.D.The Last Alliance

it''s working perfectly now thanks guys.
well it was. it loaded once, but it was upside down, so i quit and flipped the image in Gimp. now when i try to load it, it won''t. any ideas?
Targa files (like many image formats) are saved upside-down. I''m not sure why it isn''t loading now, since I can''t see your Targa loading code.

This topic is closed to new replies.

Advertisement