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 > sprite on a 3d background

#93029 - iainprice - Sun Jul 16, 2006 4:38 pm

Is it possible to display a sprite when you are using a screen for 3D?

#93044 - tepples - Sun Jul 16, 2006 6:53 pm

Make sure that the sprite's priority is equal to or less than (that is, in front of) that of BG0 and it should work. Or use a quad.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93049 - iainprice - Sun Jul 16, 2006 7:22 pm

Are there any tutorials or examples of sprites on 3d backgrounds?

#96891 - walaber - Sun Aug 06, 2006 5:43 am

hmmm, so I can't seem to get this to work... I have set the 3D bg (BG_0) priority high like so:
Code:
BG0_CR = BG_PRIORITY_3;


and when creating the sprite i set the priority to 0:
Code:
mOAM->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE;
mOAM->attribute[1] = ATTR1_SIZE_64;
mOAM->attribute[2] = 0 | ATTR2_PRIORITY(0);


but not sprite... if I change the video mode from MODE_0_3D to MODE_0_2D, obviously no 3D, but the sprite is there.

what am I doing wrong to get the sprites to show up over the 3D bg?

[edit]
Spoke too soon, it works fine on my hardware, just not on Dualis :P
_________________
Go Go Gadget NDS!

#96914 - omaremad - Sun Aug 06, 2006 3:37 pm

use MODE5_3D

it has full 2d and 3d capabilities :)

#104549 - Dark Knight ez - Sat Sep 30, 2006 11:34 am

Sorry to resurrect an old topic, but I can't get sprites working on 3D either.
My relevant pieces of code:

Code:
    SpriteEntry sprites[128];

    videoSetMode(MODE_0_3D |
                 DISPLAY_SPR_ACTIVE |    //turn on sprites
                 DISPLAY_SPR_1D |        //this is used when in tile mode
                 DISPLAY_SPR_1D_BMP      //and this in bitmap mode
                );
    BG0_CR = BG_PRIORITY_3;
   
    vramSetBankA(VRAM_A_TEXTURE);
    vramSetBankB(VRAM_B_TEXTURE);
    vramSetBankC(VRAM_C_SUB_BG);
    vramSetBankD(VRAM_D_SUB_SPRITE);
    vramSetBankE(VRAM_E_MAIN_SPRITE);

    initSpritesMain(sprites, 128);

    handlePowerupsSpritesMain(sprites, 128);

    unsigned int i;
    for(i=0; i < 128 * sizeof(SpriteEntry) / 4; i++)
       ((uint32*)OAM)[i] = ((uint32*)sprites)[i];



where initSpritesMain is:
Code:
void initSpritesMain(SpriteEntry *sprites, int array_size) {
    unsigned int i;
    for (i=0; i<array_size; i++)
      sprites[i].attribute[0] = ATTR0_DISABLED;
       
    memcpy((uint16 *)SPRITE_PALETTE, sprite_pal_bin, sprite_pal_bin_size);
   
   //copy the sprite grahics for autoblaster
    for (i=0; i< (powerup_autoblaster_bin_size >> 1); i++)
        SPRITE_GFX[i] = ((uint16*)powerup_autoblaster_bin)[i];
}


and handlePowerupsSpritesMain is:
Code:
void handlePowerupsSpritesMain(SpriteEntry *sprites, int array_size) {
    int i;
   
    // init all sprites to nothing before we start
    for (i=0; i<array_size; i++)
        sprites[i].attribute[0] = ATTR0_DISABLED;
       
    sprites[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE | 155;
    sprites[0].attribute[1] = ATTR1_SIZE_32 | 219;
    sprites[0].attribute[2] = ATTR2_PRIORITY(0);
}



For debugging purposes, I tried to display the sprite graphics on the sub screen, and that worked without a hitch. That leaves me to think it's a problem with the priorities, or maybe the copying to OAM... I don't know.
If someone has any ideas, or is willing to share some sourcecode with me that succesfully implemented sprites on top of 3D, I'd appreciate it.

#104682 - omaremad - Sun Oct 01, 2006 3:24 pm

I dont know much about mode 0 3D but i use ode 5 3D and it behaves exactly like mode 5 2D even with sprites.

#104720 - Dark Knight ez - Sun Oct 01, 2006 9:55 pm

Changing from mode 0 3D to mode 5 3D didn't help.
Can I take a look at your code?

edit:
When I disable all 3D stuff in my code and switch to mode 0 2D, the sprites are properly displayed. That means either I handle priorities wrong and the sprites are displayed behind the 3D scene, or ... ?

Priorities shouldn't be an issue though. I set the sprites priority to 0, meaning that should be displayed on top of everything. Being highest priority and all and should even be shown on top of BGs with priority 0.

What do you people use as videoSetMode(..); precisely?


2nd edit:
Bah. I know what I did wrong. Every frame I inited 3D again with a function. In that function, I kept setting the video mode to MODE_0_3D, and not enabling the sprites there as well. Commented that stuff out (it's unnecessary to be there anyway) and all is good. That's what you get when you've been working on a project for so long that you forget some of the stuff you've done to make it all work.