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 > Multiple Palettes

#176361 - singu-clarity - Wed Jul 06, 2011 9:30 am

Hi dev scene,

I just got started homebrew programming, and i'm stuck on the problem of loading multiple backgrounds with separate palettes. Here's the relevant code:

Code:

void initBG() {

   //bg uses akiraBitmap and akiraPal
   //bg2 uses testMapSharedTiles, testMapSharedPal, and Layer_1Map
   
   //bg 2 and bg 3 are both ex rot. bg 0 and 1 are text layers
   int bg = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0,0);
   int bg2 = bgInit(1, BgType_Text8bpp, BgSize_ER_256x256, 1,1);

   bgSetPriority(bg2, 1);
   bgSetPriority(bg, 2);

   dmaCopy(akiraBitmap, bgGetGfxPtr(bg), sizeof(akiraBitmap));
   dmaCopy(akiraPal, BG_PALETTE, sizeof(akiraPal));

   dmaCopy(testMapSharedTiles, bgGetGfxPtr(bg2), sizeof(testMapSharedTiles));
   dmaCopy(Layer_1Map, bgGetMapPtr(bg2),  Layer_1MapLen);

   //WHERE TO PUT SECOND PALETTE???
   dmaCopy(testMapSharedPal, BG_PALETTE, sizeof(testMapSharedPal));
}



It seems that both backgrounds refer to the palette starting from BG_PALETTE, since my second bg displays fine, but my first bg is really trippy and messed up looking (second bg has transparency).

I'm assuming that sprites have the same problem. Do most developers just use a single shared palette?

#176363 - sverx - Wed Jul 06, 2011 2:15 pm

To have separate palettes (256 colors each) for each background, you should use 'extended palettes', this way you'll be able to use up to 16 palettes (256 colors each) for each background.

#176365 - Miked0801 - Wed Jul 06, 2011 9:44 pm

For the most part, we've used a single shared palette. More from a tools support reason though then a hardware limitation.

#176366 - singu-clarity - Thu Jul 07, 2011 1:11 am

Thanks for the feedback.

@sverx: could you show me some example code to enable extended palettes? Do sprites support extended palettes as well?

@Miked0801: what tools do you use to make your backgrounds/sprites? Right now i'm just using GIMP.

#176367 - sverx - Thu Jul 07, 2011 10:00 am

Yes, you can have also 16 (256 colors each) palettes for sprites. In this tutorial page I wrote back in 2009 you can see a very simple example of background & sprite extended palettes usage, it's the first source code. Comments are in Italian but I guess it won't be so hard to understand what's going on...

#176370 - Miked0801 - Fri Jul 08, 2011 4:32 pm

Our conversion tools are in-house built; nothing I can release to the public. They do roughly the same thing as the public domain ones though: charify, palettize, etc. They also do some char reduction stuff, very useful. ProMotion and some Photoshop are the art tools we use for creation. In the (distant) past we had used DPaint for our color cycling stuff, but ProMotion does nearly the same thing now.

But even with the last few rounds of DS projects we've done, we've been able to either use shared 16-bit palettes for both sprite and BGs for the non-3D screen, and use 3D on the 3D screen :). Multiple alpha levels via A3I5 or A5I3 along with some of the other 3D features make it our mode of choice for the most part.

#176382 - PypeBros - Tue Jul 19, 2011 1:47 pm

AFAIK, the game "Tetris Attack" used to use multiple palette to handle "shading" of the game when you're K.O. It involves using one of the VRAM slot (usually VRAM_E) as a extra-palette place, but you need to map it back as LCD to enable modifications ... so it's not convenient if you're planning to do palette animations.
_________________
SEDS: Sprite Edition on DS :: modplayer

#176399 - sverx - Fri Jul 22, 2011 3:21 pm

it's completely OK to switch the VRAM bank you're using for ext palette to LCD mode -when in vblanking- to access it, the DS doesn't care when it's not drawing the screen. Just remember to set it back to ext palette mode as soon as you updated its contents.
Using multiple palettes, for instance for sprites, could be useful if you want to have enemies with different colors but just store their frames in memory once :)