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 > EXT BG and transparent colors ?

#121653 - alekmaul - Tue Mar 13, 2007 7:53 pm

Hello everyone !
I request your help because I have a little pb with my last try to write an emulator ...
I want to use 2 ext bg but I can't have a transparent color, only the BG with the highest priority is display, do you know how to setup them to use transparent EXT BGs.
Here is my init code of my BGs :
Code:

void BitmapInitArcadeMode(void) {
#define SCRGNGH 234

  // Init graphic mode
  vramSetMainBanks( VRAM_A_MAIN_BG_0x6000000, VRAM_B_MAIN_BG_0x6020000, VRAM_C_SUB_BG_0x6200000 , VRAM_D_MAIN_BG_0x6040000 );
  vramSetBankE(VRAM_E_MAIN_SPRITE);
  videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_ACTIVE );

  BG3_CR = BG_BMP8_512x512 | BG_BMP_BASE(0) | BG_PRIORITY(2) | BG_WRAP_ON;
  BG3_XDX = 1 << 8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = ((SCRGNGH / 192) << 8) | ((SCRGNGH % 192) ) ;
  BG3_CX = 0;
  BG3_CY = 0;

  BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(16) | BG_PRIORITY(0);
  BG2_XDX = 1 << 8;
  BG2_XDY = 0;
  BG2_YDX = 0;
  BG2_YDY = ((SCRGNGH / 192) << 8) | ((SCRGNGH % 192) ) ;
  BG2_CX = 0;
  BG2_CY = 0;
}


Also , my code works fine with Dualis but not with no$gba (the best emulator ?)

How, i forgot that : it is for a Ghost 'n goblins arcade emulator :D !

#121655 - Dark Knight ez - Tue Mar 13, 2007 8:13 pm

Quote:
but I can't have a transparent color

Set a pixel's value to 0. That should work.

For instance... if you would have a 128x128 bitmap (using extended rotation background) and it's using BG_BMP_BASE(0), then the following should work:

Code:
for (i=0; i<(128*128); i++) // (128*128) being the size of this BG
        BG_GFX[i] = 0; // does not show up, not having set BIT(15)


Hope that helps you out.
_________________
AmplituDS website

#121656 - alekmaul - Tue Mar 13, 2007 8:15 pm

hum ... i've made that but only the second BG is displayed (BG2 in my example)
and all is ok in dualis of course :/ ....
And you talked about bit15 but i am using 8bits BGs not 16bits, so I must use palette entries

#121664 - Sausage Boy - Tue Mar 13, 2007 8:46 pm

Unless someone has made an edit, DKe doesn't mention bit15. What he means is set the pixels value, where you normally would select which palette entry to use, to 0.

EDIT:

Oh sorry, I guess I was the one who didn't read carefully enough... Do what I said anyways, it'll hopefully work. :)
_________________
"no offense, but this is the gayest game ever"

#121739 - Dark Knight ez - Wed Mar 14, 2007 12:51 pm

If transparency can't be done in 8-bit bmps, here's a workaround... which you probably don't like.
You could make BG2 (the one which is on top) to be a 16-bit background. That would in fact fit in your current VRAM setup and transparency works like I suggested.
Drawing it would be somewhat less straightforward, but you can always do for each pixel: check what you would have written if it were 8-bit bmp, look up that palette entry in the palette you have and write that value (ORed with Bit(15)) into the 16-bit bmp.

Hope I didn't make any bad assumptions here or what-not. Just thought I'd try and help as much as I am able to.
_________________
AmplituDS website

#121741 - alekmaul - Wed Mar 14, 2007 1:11 pm

No, your idea is nice and I though about it but the pb is that it will be too slow for the emulator (I will have to write a 16 bit for each pixel so it will be 2x slow than now ...).
So I can't use this workaround... but it was a good idea, thanks for that ;).

[EDIT]Here is a screen to the game, running with Dualis
[Images not permitted - Click here to view it]

#121746 - Dark Knight ez - Wed Mar 14, 2007 2:18 pm

Nice screenshot. :)

I forgot to ask this. Does the transpancy also not work on a real NDS? You only talked about Dualis and no$gba.

Anyway, maybe my solution is too slow for an emulator, but if it's fast enough on the NDS itself... then you could still use it when you test on real hardware instead of Dualis.

I, unfortunately, see no other solutions. Except maybe to use just one BG, but I think that would be even worse, seeing as how you probably use the larger one for a scene-background which needs little updating, and the smaller one for things that can move around.
_________________
AmplituDS website

#121753 - alekmaul - Wed Mar 14, 2007 3:00 pm

Oh yes, I forgot to talk about the DS, the pb is identical than on no$gba :( only the first background is displayed ...
And the two background have different size, also the last background is scrolling so I can't combine them to make only one background.

#121758 - alekmaul - Wed Mar 14, 2007 4:32 pm

double post to say that the topic can be close, the pb was not in the bg initialization, it works fine, it was with the scrolling registers BGx_CX and BGx_CY.
it seems that Dualis does not do correct usage of the registers in bitmap mode.
Thanks for the help every one ;)