Sign in to follow this  

Problem with D3DCOLOR_ARGB

Recommended Posts

I am getting trouble when trying to find out the color of a particular pixel. I want to find out if it's NOT alpha. The check works with any 'color' aslong as it's not alpha. Any reason why it could be failing :S? Thanks.

	DWORD* traceBits = game->d3d->GetBits(trace);

        if(traceBits[currentPixel] != D3DCOLOR_ARGB(0,0,0,0)){
	    //Do stuff...

	HRESULT hResult = pTex->GetLevelDesc(0, &desc);
      return NULL;

	int width = desc.Width, 
		height = desc.Height, 
		size = width*height;
	DWORD* bits = new DWORD[size];  

	pTex->LockRect(0, &rect, 0, 0);
	memcpy(bits, rect.pBits, sizeof(DWORD)*size);

	return bits;

Share this post

Link to post
Share on other sites
D3DCOLOR_ARGB is a macro that resolves to ((D3DCOLOR)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) (essentially an integer). For the given constant values you supply to that macro, you get an integer value of zero.

Your test is thus if traceBits[currentPixel] is not zero, which is every color except transparent (0 alpha) black.

If you want to test the alpha component only, you will have to mask that component off.

Share this post

Link to post
Share on other sites
Thanks I replaced the code with:

if(traceBits[currentPixel] != 0)
state += 1;
if(traceBits[currentPixel + 1] != 0)
state += 10;
if(traceBits[currentPixel + width] != 0)
state += 100;
if(traceBits[currentPixel + width + 1] != 0)
state += 1000;

Although it still doesn't work. I checked the value and it doesn't give 0, I think there must be something wrong with the alpha channel or one of the others..
How could I mask the alpha?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this