#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:
VRAM mapping:
Sprite image loading:
And this is the function that copies the sprites to OAM:
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]; } } |