Jump to content
  • Advertisement
Sign in to follow this  

Problem with D3DCOLOR_ARGB

This topic is 3435 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

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

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

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!