Problem with D3DCOLOR_ARGB

Started by
2 comments, last by Demirug 14 years, 8 months ago
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...
        }

DWORD* Direct3D::GetBits(LPDIRECT3DTEXTURE9 pTex)
{
	D3DLOCKED_RECT rect;
	D3DSURFACE_DESC desc;
	HRESULT hResult = pTex->GetLevelDesc(0, &desc);
	if(FAILED(hResult))
      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);
	pTex->UnlockRect(0);

	return bits;
}

Advertisement
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.
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?
You need to mask out the other color channels before you compare only alpha against zero.

Something like this: (Color & 0xFF000000) != 0

This topic is closed to new replies.

Advertisement