gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Stuck at displaying sprites over 3D

#149736 - M3d10n - Thu Jan 24, 2008 6:26 pm

Hello, I'm having issues displaying sprites along with 3D. They don't show up at all, both on emulators or actual hardware.

There is one thing I don't quite understand: is SPRITE_GFX the correct place to copy my sprite graphics, even if I'm using VRAM bank F for sprites?

(I know I could use 2D quads for these sprites, but eventually I'll need to change my sprite management code so it works on the subscreen as well, so they need to be sprites).

The video mode:
Code:
videoSetMode(MODE_2_3D | DISPLAY_BG0_ACTIVE |
               DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT);


VRAM mapping:
Code:

vramSetBankA(VRAM_A_TEXTURE);
vramSetBankB(VRAM_B_TEXTURE);
vramSetBankC(VRAM_C_SUB_BG);
vramSetBankD(VRAM_D_MAIN_BG_0x06000000);   
vramSetBankF(VRAM_F_MAIN_SPRITE);


Sprite image loading:
Code:

void SpriteManager::loadImage(Sprite *sprt)
{   
   int bytes  = sprt->width*sprt->heigth;
   int offset = sprt->gfxId*(8*8); //8x8 pixels

   //Copy shorts
   //dmaCopy(sprt->image.image.data16, SPRITE_GFX, bytes/2);   
   int start = offset/2;
   for(int i = start; i<start+bytes/2; i++)
      SPRITE_GFX[i] = sprt->image.image.data16[i];

   for(int i = 0; i < 256; i++)
      SPRITE_PALETTE[i] = sprt->image.palette[i];   
}


And this is the function that copies the sprites to OAM:
Code:
void SpriteManager::render()
{      
   int spriteIndex = 0;
   Sprite *obj = mRootSprite;   
   while (obj)
   {   
      uint16 *attr = &mSpriteCache[spriteIndex].attribute[0];
      attr[0] = ATTR0_COLOR_256 | ATTR0_SQUARE | (obj->y & 0x00FF);
      attr[1] = ATTR1_SIZE_32 | (obj->x & 0x01FF);
      attr[2] = obj->gfxId;

      obj = obj->next;
      spriteIndex++;
   }   

   //Clear other sprites
   for (int i=spriteIndex; i<128; i++)
      mSpriteCache[spriteIndex].attribute[0] = ATTR0_DISABLED;

   //Copy to OAM
   for(int i = 0; i < 128 * sizeof(SpriteEntry) / 4 ; i++)
   {
      ((uint32*)OAM)[i] = ((uint32*)mSpriteCache)[i];
   }
}

#149740 - M3d10n - Thu Jan 24, 2008 6:55 pm

Oh damn.

The code above is 100% ok... it was the goddamned image loading code that was failing to load the image, thus the width and height were both 0. I just filled the sprite with 32x32 random stuff and it worked.

/punches self

#149743 - ingramb - Thu Jan 24, 2008 7:16 pm

>There is one thing I don't quite understand: is SPRITE_GFX the correct place to copy my sprite graphics, even if I'm using VRAM bank F for sprites?

Whichever vram bank is mapped to sprite graphics will show up at address SPRITE_GFX (6400000h+). Each vram bank is mapped to a different address depending on what its function is.