I guess that what happens when you code with little sleep and don't have access to a test platform

The x_inc I used (and must of accidentally deleted) is for how much the bitmap pointer needs to be incremented every time a new row is drawn. It is left at zero unless the bitmap overlaps either or both the left and right edges, Here is what I modified to hopefully work. Also one thing that I forgot to do is add some pointer type casts as even though I'm pretty sure gcc will compile this, g++ could have some issues de to the stronger C++ rules about type casts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #define WIDTH 384 #define HEIGHT 216
short * VRAM = (short*) GetVRAMAddress();
void alphaSprite(int x, int y, int width, int height, short * bitmap, short alpha) { int x_inc = 0; if (y < 0) { bitmap -= (short*)(y * width); height += y; y = 0; } if (height > HEIGHT - y) height = HEIGHT - y; if (x < 0) { bitmap -= (short*)x; width += x; x = 0; x_inc += -x; } if (width > WIDTH - x) { width = WIDTH - x; x_inc += WIDTH - (width + x); } int y_index; int x_index; short * base = (short*)(y * WIDTH) + x + VRAM; for (y_index = height; y_index > 0; --y_index, base += (short*)WIDTH - width, bitmap += (short*)x_inc) { for (x_index = width; x_index > 0; --x_index, ++base, ++bitmap) { if (*bitmap != alpha) *base = *bitmap; } } }
|