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.

Graphics > rendering on different layers

#177075 - blessingta@hotmail.co.uk - Tue Dec 06, 2011 2:08 am

I'm trying to render on different layers but what's happening is that I dont know where I can make the layers point in the oam data where I store my sprites (not the memory address as its doing now)

//all the layers shown below are pointing to the character data instead:
// how do i make them point the prite location of the memory

#define OBJ_32BIT_SPRITE (unsigned int*)0x06010000

Code:

 
   // Graphics mode controls
   //Pointer to area which controls  the graphics modes
   REG_DISPCNT = (BG3_ENABLE | BG2_ENABLE | BG1_ENABLE | BG0_ENABLE | MODE_0);
   REG_BG1CNT = (4 << 8); //point to the sprite memoory location
   REG_BG2CNT = (4 << 8); //point to the sprite memoory location
   REG_BG2CNT = (4 << 8); //point to the sprite memoory location
   REG_BG3CNT = (4 << 8); //point to the sprite memoory location
   

#177076 - Dwedit - Tue Dec 06, 2011 5:39 am

It sounds like you're a little confused here.
OAM (Object Attribute Memory) is the table that lists the sprites which will be drawn, and contains their coordinates, tiles, and other properties.

Sprites don't have layers, only tilemapped backgrounds have layers. But sprites can have different priority settings, so they can be in front of some background layers and behind others.

VRAM (Video RAM) is divided into two sections, one for tilemapped backgrounds (0x06000000), and one section for sprites (0x06010000). Sprites may only use the VRAM devoted to sprites, and tilemapped backgrounds may only use the VRAM dedicated to tilemapped backgrounds. They can not be shared. The only exception is one of the bitmap modes which lets you use the first half of sprite VRAM as framebuffer pixels, then that area can't be used for sprites, but bitmap modes are generally pointless anyway.

Here's the specification of the BGxCNT registers (from GBATEK):
Code:

4000008h - BG0CNT - BG0 Control (R/W) (BG Modes 0,1 only)
400000Ah - BG1CNT - BG1 Control (R/W) (BG Modes 0,1 only)
400000Ch - BG2CNT - BG2 Control (R/W) (BG Modes 0,1,2 only)
400000Eh - BG3CNT - BG3 Control (R/W) (BG Modes 0,2 only)

  Bit   Expl.
  0-1   BG Priority           (0-3, 0=Highest)
  2-3   Character Base Block  (0-3, in units of 16 KBytes) (=BG Tile Data)
  4-5   Not used (must be zero)
  6     Mosaic                (0=Disable, 1=Enable)
  7     Colors/Palettes       (0=16/16, 1=256/1)
  8-12  Screen Base Block     (0-31, in units of 2 KBytes) (=BG Map Data)
  13    Display Area Overflow (0=Transparent, 1=Wraparound; BG2CNT/BG3CNT only)
  14-15 Screen Size (0-3)


The highest value for a character base block is 3, since there are two bits dedicated to that field. You can't specify 4 and share it with the sprites, that instead puts a 1 in the "not used" field. If you specify base block 3, and attempt to use high-numbered tiles which would be inside sprite memory, it draws some vertical stripes instead of tile graphics.
But you still need to specify where you want to put your tilemap map. It's specified in 2KB units. Leaving this at 0 for all 4 layers is not the correct way to do it. The memory area for the maps is shared with the memory area for tile graphics. After you have your maps set up and working, you will see some garbage-looking tiles in a Tile Viewer, that's your map displayed as tile graphics.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#177082 - blessingta@hotmail.co.uk - Wed Dec 07, 2011 2:56 pm

Oh sorry I meant to say that my issue was that because of Rg_bg1cnt... (which I had to put to stop the background being littered with random squares). But now the issue is that my sprite "redcircle no longer renders on screen"

Code:
 // Graphics mode controls
   //Pointer to area which controls  the graphics modes
   REG_DISPCNT = (BG3_ENABLE | BG2_ENABLE | BG1_ENABLE | BG0_ENABLE | MODE_0);
   REG_BG1CNT = (4 << 8); //point to the sprite memoory location
   REG_BG2CNT = (4 << 8); //point to the sprite memoory location
   REG_BG2CNT = (4 << 8); //point to the sprite memoory location
   REG_BG3CNT = (4 << 8); //point to the sprite memoory location
   


http://postimage.org/image/bkbea23i7/8669132f/

Code:

void redcircle_sprites()
{//2x2 size
//priority = leayer
int i_layer = 1;
int i_x_sp = 0, i_y_sp = 0;
   psMy_OAM_Sprites16[1 * 4 + 0] = ((0<<14)|(0<<7)|(i_y_sp<<0));
    psMy_OAM_Sprites16[1 * 4 + 1] = ((1<<14)|(0<<13)|(0<<12)|(0<<8)|(i_x_sp<<0));
    psMy_OAM_Sprites16[1 * 4 + 2] = ((0<<12)|(i_layer<<10)|(0<<8)|(8<<0));
    psMy_OAM_Sprites16[1 * 4 + 3] = 0;

}

#177087 - blessingta@hotmail.co.uk - Thu Dec 08, 2011 4:41 pm

problem solved, forgot to activate objs