# 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.

## 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 on other sites
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 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 on other sites
Another alternative but a bit faster (sort of what Axisverse is working with):

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

##### 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 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.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633758
• Total Posts
3013712
×