GP32 Indexing Into A 16-bit Array For Gamepark Sdk


generalnmx

Playful/Fascist Mod
Joined
Apr 18, 2003
Messages
2,128
Age
43
Location
Maryland, USA
Website
www.matts-hosting.com
Hey, that rhymes. Anyway, I suck. Here's why:

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 IGfxDrawPixel() 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?
 
At a guess, shouldn't i be set to zero for each row of the sprite? That would mean just moving the "i=0;" to after the "for (y = yScreen...".

Just interested, you're in America, why do you use "colour"? Not that I'm complaining, I'm sick of how all Americans mis-spell words like that :D
 
I fixed the function, thanks to Dalto. And I learned why large arrays should be declared const (Dalto's previous version of imageconvertor didn't declare it const), as after that my problem fell down to a single unsigned char pgFlip = 1; global variable at the top of a source file.

Oh, and I use some UK spellings because one of my grade school teachers came from England. She always spelled words that way, and I kinda picked it up as I had a crush on her (she was about 24). She also crossed her 7s and Zs in the middle, which I also picked up.
 
Back
Top