comparing apples and oranges!?

Started by
1 comment, last by tadobie 19 years, 6 months ago
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;
		if(colour == COL_COLLISION)
		{
			Surface->UnlockSurface(overlapRect);
			return true;
		}
       }

Don't mug ya self!
Advertisement
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.
----------------------------------------http://www.sidema.be----------------------------------------
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?
Don't mug ya self!

This topic is closed to new replies.

Advertisement