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.

Beginners > Together Sprite&Background displaying

#168578 - semihce - Thu May 07, 2009 2:48 pm

Hi everybody,

I want to display Sprite and Background images together. When I want to display only background or sprite, it is ok, I can display them seperately.
But when I want to display them together, I got an orange background and my sprite stands there. What happens to my background image?

Here are my defines:
Code:
// Set graphics mode
#define SCREENMODE_0    0x0     ///< Enable screen mode 0
#define SCREENMODE_1    0x1     ///< Enable screen mode 1
#define BG1_ENABLE      0x200   ///< Enable background 1
#define OBJMAP_1D       0x40    ///< 1D object(sprite) mapping
#define OBJ_ENABLE      0x1000   ///< Enables sprites


When I want to display only background, I use this code:
Code:
setMode( SCREENMODE_0 | BG1_ENABLE | OBJMAP_1D );


And when I want to display only sprite, I use this code:
Code:
setMode( SCREENMODE_0 | OBJ_ENABLE | OBJMAP_1D );


And now, What should I do in order to display both of them together? Please help me..

Here is a link to the GBA output:
http://ktuce.ktu.edu.tr/~baysemi/GameRevolution.gba

#168579 - Ruben - Thu May 07, 2009 3:49 pm

From what you've said, it should be
Code:
setMode( SCREENMODE_0 | OBJ_ENABLE | BG1_ENABLE | OBJMAP_1D );


However, looking at the binary, it seems that BG0 is the one that holds the correct data so this should be

Code:
setMode( SCREENMODE_0 | OBJ_ENABLE | BG0_ENABLE | OBJMAP_1D );

#168580 - semihce - Thu May 07, 2009 4:43 pm

Ruben wrote:
From what you've said, it should be
Code:
setMode( SCREENMODE_0 | OBJ_ENABLE | BG1_ENABLE | OBJMAP_1D );


However, looking at the binary, it seems that BG0 is the one that holds the correct data so this should be

Code:
setMode( SCREENMODE_0 | OBJ_ENABLE | BG0_ENABLE | OBJMAP_1D );


I have done this but still I got the same result

#168581 - Ruben - Thu May 07, 2009 4:44 pm

Well, the #define for BG0 should be 0x0800.. what is the definition of setMode? Is it a libgba function? If so, I'm not much help. :P

#168582 - semihce - Thu May 07, 2009 5:13 pm

Ruben wrote:
Well, the #define for BG0 should be 0x0800.. what is the definition of setMode? Is it a libgba function? If so, I'm not much help. :P


Here my definitions:

Code:
#define BG0_ENABLE      0x100   ///< Enable background 0
#define BG1_ENABLE      0x200   ///< Enable background 1
#define BG2_ENABLE      0x400   ///< Enable background 2
#define BG3_ENABLE      0x800   ///< Enable background 3
#define OBJ_ENABLE      0x1000  ///< Enable sprites
#define REG_DISPCNT   (*(volatile u32*)0x4000000)


And here is setMode function:

Code:
void Lypson_Graphics::setMode(u16 mode)
{
   REG_DISPCNT = mode;
}

#168583 - Ruben - Thu May 07, 2009 5:19 pm

Er, my bad, it should've been 0x100, so that's fine..

DISPCNT is a 16-bit non-volatile register.. that is..

Code:
#define REG_DISPCNT   (*(u16*)0x4000000)


EDIT: I wrote 32-bit... maybe that's a sign that I should sleep :P
EDIT 2: Can you upload a binary with BG0 on?

#168585 - semihce - Thu May 07, 2009 5:52 pm

ok, thank you very much.. when I tried this code, it worked

Code:
setMode( SCREENMODE_0 | OBJ_ENABLE | OBJMAP_1D | BG0_ENABLE );