PDA

View Full Version : Can I define "transparent color" in openGL?



jxruan
07-17-2001, 11:33 AM
Is there "transparent color" in openGL which
means that a primitive or object with this
color is totally transparent?

Here is my problem:
I have a 256*256 gray-scale bitmap and
its corresponding mask, which is a binary
bitmap of the same size. The mask specifies
the boundary of the gray-scale one.
Instead of texture-mapping the bitmap onto
a square area, I want those pixels outside
the boundary to be transparent, so people
can see objects behind them.

DFrey
07-17-2001, 12:11 PM
Yes, there are a few ways to do that. The easiest being changing the grayscale bitmap to a RGBA image. You put your grayscale data in the RGB channels, and your mask in the A channel. Then you just use alpha testing to reject the masked portion. If you want to get a little more complicated you could put the image into a 16 bit RGB, and convert it into a luminance-alpha texture when you load it. Or an another approach is to use the interpolation combiner of the GL_texture_env_combine extension along with alpha testing.

[This message has been edited by DFrey (edited 07-17-2001).]

jxruan
07-19-2001, 04:20 AM
Thank you.
I used the luminance-alpha texture and it worked well. But there came another problem. Actually, I have three texture planes and they are orthodox to each other, say 'xy', 'yz', 'zx'. Because the tranparency depends on the sequence of your rendering, suppose here I render 'xy' first, then 'yz' and then 'zx', I got the following effect:
1. 'xy' can be seen completely.
2. some part of 'yz' is cut off by the
transparent part of 'xy'.
3. some part of 'zx' is cut off by the
transparent part of the above two.
The reason was that when using alpha value
to achieve transparent effect, it in fact
lets the transparent area to have the color
of its background, a "fake" transparent. So to the 'yz' and 'zx' plane, the transparent part of 'xy' is not "transparent'. In fact,
it has the color of the background when 'xy' plane was texture-mapping.
Is there any way to solve it? The solution that I can fingure out is to texture my image to a polygon. What a complex job!



Originally posted by DFrey:
Yes, there are a few ways to do that. The easiest being changing the grayscale bitmap to a RGBA image. You put your grayscale data in the RGB channels, and your mask in the A channel. Then you just use alpha testing to reject the masked portion. If you want to get a little more complicated you could put the image into a 16 bit RGB, and convert it into a luminance-alpha texture when you load it. Or an another approach is to use the interpolation combiner of the GL_texture_env_combine extension along with alpha testing.

[This message has been edited by DFrey (edited 07-17-2001).]

DFrey
07-19-2001, 04:47 AM
It sounds like you implemented alpha blending rather than alpha testing. If you use alpha blending, you must disable (mask) depth writing, and depth sort the alpha blended polygons with respect to one another before drawing them. If you use alpha testing you can leave depth writing enabled, and no sorting is necessary.

jxruan
07-19-2001, 04:57 AM
Yeah, I used the blending. It had been all
set after I used alpha-testing as you
mentioned. Thanks a lot.