Archived

This topic is now archived and is closed to further replies.

qx452

transparent texturing

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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!]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites