Jump to content
  • Advertisement
Sign in to follow this  

looking for a color in a RECT

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

The following code has an infinite loop in it. Since this doesn't work, can someone explain why? All I want to do is to detect if a certain color is inside a given RECT. Anyone know how?
	//thid function declares and Zeros the struct
	DDSURFACEDESC2 sd = Attacker->GetSurfaceDesc();
	RECT rct = GetOverlapRect(GetSizeRect(Attacker), 
        //this function calls lock for the surface
	Surface->LockSurface(rct, sd);

	LPDWORD pixels = (LPDWORD)(sd.lpSurface);
	DWORD colour = pixels[0];

	for(int i=0;i<sizeof(pixels);i++)
		colour = pixels;
		if(colour == COLLISION_COLOR)
                   //this function calls unlock for the surface
			return true;
	return false;

Share this post

Link to post
Share on other sites
A few comments on that code:
  • sizeof(pixels) is always 4 (on 32-bit CPUs) because pixels is a pointer.
  • This line is redundant: DWORD colour = pixels[0]; since colour is overwritten in the loop.
  • UnlockSurface() isn't called if theres no collision.
  • I don't see any infinite loop in that code.

    You want to change your loop so that its:
    for(int i=0;i<(rct.right-rct.left)*(rct.bottom-rct.top);i++)
    So you loop for each pixel in the RECT.

    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!