generalnmx
Playful/Fascist Mod
Hey, that rhymes. Anyway, I suck. Here's why:
yScreen = where to start drawing on the screen for Y
xScreen = where to start drawing on the screen for X
lookup->sHeight = the sprite's height
lookup->sWidth = the sprite's width
((ushort16*)spriteset->voidPtr) is a 16-bit array (yes, it's valid) from a 24-bit bitmap converted to a header file by GP32 Convertor
spriteset->trans = transparent colour to skip
lookup->indX = index into 16-bit array for X (the actual index should be x+y*array_width, right?)
lookup->indY = index into 16-bit array for Y, IE where to start taking pixels from
spriteset->width = width of array
spriteset->height = width of array
Everything works when I just call GpTransBlt16 using the above variables, but when I try to do it myself, everything goes to hell. Now I know plotting on the screen is right (the for loops), since it's actually drawn at the correct location on the screen. Just what's drawn is garbage, albiet all colours from the 16-bit image's array. I also know my implementation of IGfrawPixel() works, since I called it outside of that function.
You may wonder why I'm making my own function when GpTransBlt16 works. Well, first off, the Gamepark SDK sucks. And why it sucks is because GpPointSet16 (to set a single pixel of colour on the screen) doesn't work, and worse yet, GpTransLRBlt16 doesn't work either (GpBitLRBlt16 does)! The latter mirrors the image vertically, which any side-scroller or isometric game needs.
I know my problem has to do with indexing into the 16-bit image's array. So, what am I screwing up?
Code:
void_ IGfxDrawPixel(const_int32 x, const_int32 y, const_ushort16 colour)
{
ushort16 *fbuffer;
fbuffer = (ushort16*)(gpFramebuffer[pgFlip].ptbuffer); /* the framebuffer is actually 16-bit in 16-bit mode */
*(fbuffer + (x*240) + (239-y)) = colour; /* the framebuffer is structured oddly, so we need to index this way */
} /* end of IGfxDrawPixel() */
/* draws a single sprite on the screen */
void_ IGfxDrawSprite(const_int32 xScreen, const_int32 yScreen,
IMAGESET* spriteset, SPRITEINFO* lookup)
{
short16 x,y, i;
ushort16 colour;
if (spriteset && lookup) /* sanity check */
{
i = 0;
for (y = yScreen; y < yScreen+lookup->sHeight; y++) {
for (x = xScreen; x < xScreen+lookup->sWidth; x++) {
colour = *(((ushort16*)spriteset->voidPtr) + (lookup->indX + (lookup->indY * spriteset->width)) + i++);
if ( colour != spriteset->trans)
IGfxDrawPixel(x,y,colour);
} /* end for */
} /* end for */
} /* end if */
} /* end of IGfxDrawSprite() */
yScreen = where to start drawing on the screen for Y
xScreen = where to start drawing on the screen for X
lookup->sHeight = the sprite's height
lookup->sWidth = the sprite's width
((ushort16*)spriteset->voidPtr) is a 16-bit array (yes, it's valid) from a 24-bit bitmap converted to a header file by GP32 Convertor
spriteset->trans = transparent colour to skip
lookup->indX = index into 16-bit array for X (the actual index should be x+y*array_width, right?)
lookup->indY = index into 16-bit array for Y, IE where to start taking pixels from
spriteset->width = width of array
spriteset->height = width of array
Everything works when I just call GpTransBlt16 using the above variables, but when I try to do it myself, everything goes to hell. Now I know plotting on the screen is right (the for loops), since it's actually drawn at the correct location on the screen. Just what's drawn is garbage, albiet all colours from the 16-bit image's array. I also know my implementation of IGfrawPixel() works, since I called it outside of that function.
You may wonder why I'm making my own function when GpTransBlt16 works. Well, first off, the Gamepark SDK sucks. And why it sucks is because GpPointSet16 (to set a single pixel of colour on the screen) doesn't work, and worse yet, GpTransLRBlt16 doesn't work either (GpBitLRBlt16 does)! The latter mirrors the image vertically, which any side-scroller or isometric game needs.
I know my problem has to do with indexing into the 16-bit image's array. So, what am I screwing up?