View Full Version : hiding colors

23-01-2004, 04:56 PM
please help!
What i need most to use sprites in Opengl is that a special transparent color is hidden and the rest is drawn on screen with color values as in the source texture. How can that be done ? What i don't need is transparency for all pixels or alpha, i want simply to hide a color.

Can somebody explain how to get this result with BLENDING. Or what would be the best way around ? I have read a tutorial on www.delphigl.de that shows how trees are displayed, making one color transparent through using a second monochrome texture with the needed alpha values. Maybe i have to use this way.. :?:

23-01-2004, 06:35 PM
The most obvious way is to use alpha testing. What you need to do:

Load up your texture. Generate an alpha channel for it, specifying 0 as transparent pixels and non-zero for the opaque pixels of your sprite -- this can be done with a simple loop over the pixels. Next, glEnable(GL_ALPHA_TEST) and set a GL_ALPHA_FUNC as appropriate (e.g. glAlphaFunc(GL_GREATER, 0.0)). Alpha testing simply means "Check the alpha value for the texture here, and if it doesn't pass the test then discard the fragment completely." In other words, fragments must have alpha > 0 to pass the test or they're considered transparent. Once you've dealt with the sprites then remember to disable alpha testing (if required) so it doesn't affect other textures.

Let me know if you want an example.

23-01-2004, 08:39 PM
Thanks, Alimonster. I have managed it with your valueable help.