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 > two backgrounds on same screen = garbage?

#72670 - PFM - Mon Feb 20, 2006 10:38 pm

I'm currently trying to build an adventure-game and need two bmp16-backgrounds on the main-screen and two (bmp16 and map) on the sub screen.
The main-screen should display a jpeg on BG2. BG3 is initialized because i have in mind to display some animated stuff over the jpeg.

The sub-screen should display a jpeg on BG2 and some text on BG3.

Problem is, i don't know how to adress the single backgrounds. If i use BG_GFX or BG_GFX_SUB it simply put's the image-data in the vram.
The two backgrounds on the main-screen both display the same image, while the sub-screen displays the image on BG2 and some garbage on BG3.

I can't find any examples on how to do this.


Initializing the screens/bgs:
Code:
videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE);
   
vramSetMainBanks(VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_BG_0x6020000, VRAM_C_SUB_BG, VRAM_D_LCD);
   
BG2_CR = BG_BMP16_256x256;
BG3_CR = BG_BMP16_256x256;
SUB_BG2_CR = BG_BMP16_256x256;
SUB_BG3_CR = BG_MAP_BASE(31);

BG_PALETTE_SUB[255] = RGB15(31,31,31);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   
lcdSwap();
   
BG2_XDX = 1<<8;
BG2_XDY = 0;
BG2_YDX = 0;
BG2_YDY = 1<<8;
BG2_CX = 0;
BG2_CY = 0;
   
BG3_XDX = 1<<8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1<<8;
BG3_CX = 0;
BG3_CY = 0;
   
SUB_BG2_XDX = 1<<8;
SUB_BG2_XDY = 0;
SUB_BG2_YDX = 0;
SUB_BG2_YDY = 1<<8;
SUB_BG2_CX = 0;
SUB_BG2_CY = 0;
   
SUB_BG3_XDX = 1<<8;
SUB_BG3_XDY = 0;
SUB_BG3_YDX = 0;
SUB_BG3_YDY = 1<<8;
SUB_BG3_CX = 0;
SUB_BG3_CY = 0;


Displaying the images:
Code:
memset(BG_GFX, 0, 256*256*2);
BltImage(test_jpg, BG_GFX, 256, 192);
   
memset(BG_GFX_SUB, 0, 256*256*2);
BltImage(test_jpg, BG_GFX_SUB, 256, 192);


Would be great if someone could help me with this.