Sign in to follow this  
tadobie

comparing apples and oranges!?

Recommended Posts

From what I understand lpSurface is the memory address of the pixels in the surface. If this is the case how can I get access to the actual pixel colour value so I can compare it to an RGB color value as in the line: if(colour == COL_COLLISION)
	Surface->LockSurface(overlapRect, sd);

	LPDWORD pixels = (LPDWORD)(sd.lpSurface);
	
	DWORD colour;
	
        for(int i = 0; i < (overlapRect.right-overlapRect.left)*(overlapRect.bottom-overlapRect.top); i++)
        {
		colour = pixels[i];
		if(colour == COL_COLLISION)
		{
			Surface->UnlockSurface(overlapRect);
			return true;
		}
       }

Share this post


Link to post
Share on other sites
Actually, you need to know different things such as the color format the surface is stored it. Dependently on that, you have either to decode it or compare it to a value that represents the collision color in that given color format.

What you need to know is that the number of bytes representing a color depends on the bitdepth of the surface. A 16 bit surface (being it 565, 1555, X555, ...) stores one pixel in 2 bytes. A 24 bit surface in 3 bytes and a 32 bit surface in 4 bytes.

Dependently on the bitdepth you have to a) read in the pixels, b) iterate through the bitmap and c) compare the value.

Share this post


Link to post
Share on other sites
The bit depth is 16 bits,
the color I want to compare in collision is RGB(1, 1, 1)
How would i go about iterating through the array and comparing the pixel values with the collision color?

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