Extended Palettes and Transparency

Post Reply
WeiPhil
Posts: 2
Joined: Wed Jul 03, 2019 11:00 pm

Extended Palettes and Transparency

Post by WeiPhil » Thu Jul 04, 2019 9:23 pm

Hello everyone,
I'm a new developer on nintendo ds and I'm trying to build some simple examples to test the feature of the nintendo ds. In the quest doing this I marched upon Extended Palettes which seem to be new compared to the gba. If I understand correctly the idea is that you can sacrifice some ram to have a maximum of 16*256 colors per background instead of juste 256 for the main or the sub and would hence allows for much richer graphics.

So I tried to setup the extended palette in the same fashion that the exemples at https://github.com/devkitPro/nds-exampl ... ackgrounds, (I noted that I had to set the while loop to true to work on desmume for some reason even if it works on the ds). So far so good now the problem is I wanted to use the extended palette with some tiled graphics.More specifically a tiled background on the sub engine bg 2 with tiles and palette generated by grit and a custom map and also a bg 1 with text that would be mapped manually from tiles and palette generated with grit too.
I could achieve to have both backgrounds displayed but I still have a minor problem because my text background is not transparent. So I was wondering if this is expected with extended palettes or not.
Here are some of the relevant calls that summarize what I have done:

Code: Select all

   bgExtPaletteEnableSub();

    vramSetBankC(VRAM_C_SUB_BG);
    videoSetModeSub(MODE_0_2D);
    int bg1Sub = bgInit(1, BgType_Text8bpp, BgSize_T_256x256, 1, 2);
    int bg2Sub = bgInit(2, BgType_Text8bpp, BgSize_T_256x256, 1, 0);

    dmaCopy(menuButtonTiles, (void *)bgGetGfxPtr(bg2Sub), menuButtonTilesLen);

    vramSetBankH(VRAM_H_LCD); // for sub engine

    dmaCopy(menuButtonPal, (void *)&VRAM_H_EXT_PALETTE[bg2Sub - 4][0], menuButtonPalLen);

    vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); // for sub engine

    dmaCopy(backgroundTextMap, (void *)bgGetMapPtr(bg2Sub), backgroundTextMapLen);    

    dmaCopy(ocrFontTiles, bgGetGfxPtr(bg1Sub), ocrFontTilesLen);

    vramSetBankH(VRAM_H_LCD); // for sub engine
    dmaCopy(ocrFontPal, &VRAM_H_EXT_PALETTE[bg1Sub - 4][0], ocrFontPalLen);
    vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);

    // setting map manually with bgGetMapPtr(bg1Sub)[pos] = ...


I set the grit like this for the bg2:

Code: Select all

-g -gt -gB8 -p -m -mR8 -gTFF00FF
And for the text

Code: Select all

-g -gt -gB8 -p -m! -mR! -gTFF00FF
both images use the correct color 0xFF00FF as transparnet background color

And the result is the following one :
Screenshot 2019-07-04 at 22.20.40.png
(206.9 KiB) Not downloaded yet
Thx for reading and if anyone has an idea where this come from or could explain me the limitations of extended palettes it would be great!

WinterMute
Site Admin
Posts: 1404
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Extended Palettes and Transparency

Post by WinterMute » Fri Jul 05, 2019 3:47 pm

It's been a while since most of us dealt with DS code so please bear with us.

The first thing that pops out is that the first dimension on the *_EXT_PALETTE array is the hardware background number. The return value from bgInit is an internal id & not related to hw background. You should use the hardware background number you asked for in the bgInit call in this code.

Code: Select all

 dmaCopy(menuButtonPal, (void *)&VRAM_H_EXT_PALETTE[bg2Sub - 4][0], menuButtonPalLen);
i.e. 2, not bg2Sub -4.

I'll need to dig through some code to check if the -gT parameter works as expected here - iirc it was definitely supposed to. It would help a lot if you provided your code & source images for us to check what's actually happening.
Help keep devkitPro toolchains free, Donate today

devkitPro IRC support
Personal Blog

WeiPhil
Posts: 2
Joined: Wed Jul 03, 2019 11:00 pm

Re: Extended Palettes and Transparency

Post by WeiPhil » Sun Jul 07, 2019 7:00 pm

Hi, and first of all thx for the response!
Thx to your note I finally found out what was wrong not directly but looking at how I generated my backgrounds, I was simply not giving enough space to my tiles in the vram (some wrong map_base, tile_base combination)! Everything's working like a charm now!

But while I'm at it I have another question regarding grit, I just can't figure out how I should give the parameters to make a shared palette from multiple png's. For example if I have a.png , b.png and c.png and I would like to generate the tiles for each one, no map (because I'll use it for sprites) and a shared palette for all of them.
Probably using the template makefile can't handle such case for grit no? I tried then to generate it manually using:

Code: Select all

grit a.png b.png c.png -W3 -g -gt -gB8 -Mh4 -Mw4 -m! -p -pS -S a.s b.s c.s -O abc
But this doesn't seem to work.
Any clue on how to use the -pS option correctly?
Best,
Philippe

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests