I ran into a color issue when using memset() that produces colors not at all what they should be.
Basically, I want to fill a square of the screenBuffer with a particular color. This works fine for black (0x0000) and white (0xFFFF), but everything else gets screwy.
Here's a code snippet:
I'm pretty sure the problem stems from the color being written into memory with incorrect sizing. (Black and white work fine because all 0's or all 1's being misaligned across byte boundries is ok.)
I'd like a quicker method of filling a square than writing a color directly into each PIXEL of the screenBuffer.
Can one of you guys help out?
Thanks,
Andre
Basically, I want to fill a square of the screenBuffer with a particular color. This works fine for black (0x0000) and white (0xFFFF), but everything else gets screwy.
Here's a code snippet:
- Code:
void square( short x1, short y1, short x2, short y2, PIXEL color )
{
for (short v = y1; v < y2; v++)
memset( gScreenBuffer+(v*SCREEN_WIDTH+x1), color, sizeof(PIXEL)*(x2-x1) );
}
I'm pretty sure the problem stems from the color being written into memory with incorrect sizing. (Black and white work fine because all 0's or all 1's being misaligned across byte boundries is ok.)
I'd like a quicker method of filling a square than writing a color directly into each PIXEL of the screenBuffer.
Can one of you guys help out?
Thanks,
Andre