Skip to main content
GameDev.net gamedev.net
🔒 Locked

transparent texturing

Started by qx452 Dec 15, 2001 at 7:27 PM 4 replies 350+ views
Original Post
qx452
qx452
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?
Null and Void
Null and Void
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!]
Brannon
Brannon
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
Brannon
Brannon
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
qx452
qx452
Thanks I got it working.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.