Jump to content
  • Advertisement
Sign in to follow this  
Antonym

testing alpha channel

This topic is 3352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I want to test the alpha channel in d3d. Right now my test is.
if(bits[currentPixel] == D3DCOLOR_ARGB(0,255,255,255))

How can I make it so that I only test the alpha channel and not have to take into account the other colors? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
So a color is made of four bytes, one for each of A, R, G, B. You can get the alpha channel by just looking at the first bit. This should be the one furthest left, so you can just move it right. You can simply do (bits[currentPixel] >> 24) to get the value of the alpha of that pixel.

Share this post


Link to post
Share on other sites
Don't forget that the hardware can also do it for you using D3DRS_ALPHATESTENABLE, D3DRS_ALPHAFUNC and D3DRS_ALPHAREF.

http://msdn.microsoft.com/en-us/library/ee415138%28VS.85%29.aspx

Share this post


Link to post
Share on other sites
Another alternative but a bit faster (sort of what Axisverse is working with):

if( bits[currentPixel] & 0xff000000 ) // alpha is set

Share this post


Link to post
Share on other sites
Thanks guys. I was wondering, does it work to set alpha aswell? How would I do it if I wanted to set alpha to a particular value?

Share this post


Link to post
Share on other sites
Quote:
How would I do it if I wanted to set alpha to a particular value?

bits[currentPixel] = ( bits[currentPixel] & 0xffffff ) + (alphaVal << 24);

where alphaVal >=0 and <= 255.

The "& 0xffffff" preserves rgb and clears the "old" alpha value.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!