transparent texturing

Started by
4 comments, last by qx452 22 years, 4 months ago
For a 2D game, I want to put a texture onto a quad so that a certain color is 100% transparent. Like a color key in DirectDraw. I looked around for this but I couldnt find anything because I dont know what its called. What is it called? And how can I do it?
Advertisement
You can do it through an alpha channel and either alpha testing (faster, but less options) or blending (slower, but more options). While you''re reading the texture into a buffer, test each pixel. If the pixel is the color you want transparent, insert an alpha value of 0x00, otherwise insert an alpha value of 0xFF. Make sure to retain the alpha channel by storing the texture as GL_RGBA internally.

[Resist Windows XP''s Invasive Production Activation Technology!]
I have been trying something similar. The software implementation of OpenGL (the MS version anyway) doesn't support blending, so I wanted to make this work via alpha testing.. but how exactly does that work? I have tried enabling GL_ALPHA_TEST, and setting the alpha func to GL_NOTEQUAL, 0.0f (thinking that would make any pixels with an alpha channel not equal to zero pass the test and thus be rendered into the color buffer), but that doesn't seem to work. Actually, it does something, but not what I want. The pixels that should be "transparent" are rendered as white pixels. Am I missing something? (I want pixels with an alpha channel equal to zero to be transparent) Also, I am setting the GL_TEXTURE_ENV_MODE to GL_DECAL, so the current glColor() value shouldn't affect anything right?

Also, I am processing the image during load to insert an alpha channel and set it appropriately (I have a certain RGB tuple I look for to determine which pixels get alpha 0x00, or alpha 0xff. And I am specifying GL_RGBA for the internal format and image format in glTexImage2D().

-Brannon

Edited by - Brannon on December 16, 2001 5:36:55 AM
-Brannon
Well, OpenGL does not support color-key transparency, so, as others pointed out, you hace to use either blending or alpha test.

The reason why alpha test does not work with GL_DECAL is that GL_DECAL already performs some kind of alpha test. Try using GL_REPLACE instead, this should work!

-Lev
Cool, that did it. I didn''t see anything in the documentation about GL_DECAL would screw up the alpha test. Oh well. Thanks!


-Brannon
-Brannon
Thanks I got it working.

This topic is closed to new replies.

Advertisement