#115684 - nio101 - Thu Jan 18, 2007 11:38 am
Hello,
I'm quite new to DS dev, and I try to use a 512x512 8bit background along with a 256x256 8bit one on the main screen.
The idea is to switch from one background to another by using priorities...
I use the following code :
Code: |
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE );
vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_BG,
VRAM_C_SUB_BG , VRAM_D_MAIN_BG);
BG3_CR = BG_BMP8_512x512 | BG_BMP_BASE(0) | BG_PRIORITY(3);
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
BG3_CX = 64 << 8;
BG3_CY = 64 << 8;
dmaCopy(512x512Bitmap_bin, BG_GFX, 512*512);
dmaCopy(Master_Pal_bin, BG_PALETTE, 256*2);
BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(16) | BG_PRIORITY(0);
BG2_XDX = 1 << 8;
BG2_XDY = 0;
BG2_YDX = 0;
BG2_YDY = 1 << 8;
BG2_CX = 0;
BG2_CY = 32 << 8;
dmaCopy(256x256Bitmap_bin, VRAM_D , 256*256);
|
But the second background doesn't show up...
I've read tutorials and a lot of topics about background setups, but I couldn't find the solution...
Thanks for your help!
#115686 - Lick - Thu Jan 18, 2007 11:42 am
Copy the second backgrounds data, per 2 bytes, while setting bit15 (which is the alpha bit). Also, for the right BG_BMP_BASE, you can use BG_BMP_RAM(n) for this purpose.
for(...)
((u16*)BG_BMP_RAM(16))[i] = ((u16*)data)[i] | (1<<15);
_________________
http://licklick.wordpress.com
#115689 - nio101 - Thu Jan 18, 2007 11:59 am
Thanks for your answer but it still doesn't work...
-EDIT- : It doesn't work with Dualis, BUT it DOES work with NDESMUME ! I'm curious to know why !?!
For my understanding, why should we set the bit15 for the second background, and not for the first one ?
Thanks!
#115690 - Lick - Thu Jan 18, 2007 12:14 pm
Oops, sorry. I was mistaken (thought you were using 16bit). Just try this:
dmaCopy(256x256Bitmap_bin, (u16*)(BG_BMP_RAM(16)), 256*256);
_________________
http://licklick.wordpress.com
#115692 - nio101 - Thu Jan 18, 2007 12:32 pm
Great, it's working ! thanks !
Now I have 2 backgrounds, I've tried to switch from one to another, but I didn't manage to do it !?! I've tried using setvideomode (but I guess it shouldn't be used that way) and altering BG2_CR and BG3_CR to modify BG_PRIORITY(X), but it didn't work...
If anybody can help... thanks again !
(too bad DEV Scene tutorials didn't do further day4...)
#115698 - Dark Knight ez - Thu Jan 18, 2007 1:41 pm
If you have BG_PRIORITY(0), the BG is the top-most background shown.
If you have BG_PRIORITY(3), it is the bottom-most background shown.
Values in between are possible, with an ordering effect.
So yes, you have to set the BG_PRIORITY, and make sure you set the priorities right. I guess people might think the values to work the other way around.
If you think you set the values right, post some code here so people can comment on it.
_________________
AmplituDS website
#115701 - HyperHacker - Thu Jan 18, 2007 1:48 pm
You have allocated 320K of VRAM for this, correct? 512x512 backgrounds are painful on VRAM usage; even at 8-bit that's 256K.
_________________
I'm a PSP hacker now, but I still <3 DS.
#115706 - nio101 - Thu Jan 18, 2007 2:26 pm
Yes, tu sum it up, I need to switch between a 512x512/8bit background and a "simple" 256x256/8bit on the main screen.
The following code I use doesn't allow to switch priorities... I only tested it with Dualis and NdesMume (since I don't have my DS with me ATM).
BTW, Dualis doesn't show the second background, while NdesMume does. Perhaps it's due to the fact that I'm heavy on VRAM with my 512x512 8 bit bitmap...?
Thanks.
Code: |
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG2_ACTIVE );
vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_BG,
VRAM_C_SUB_BG , VRAM_D_MAIN_BG);
BG3_CR = BG_BMP8_512x512 | BG_BMP_BASE(0) | BG_PRIORITY(1);
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
BG3_CX = 64 << 8;
BG3_CY = 64 << 8;
dmaCopy(Master_Pal_bin, BG_PALETTE, 256*2);
dmaCopy(LargeBitmap_bin, BG_GFX, 512*512);
BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(16) | BG_PRIORITY(0);
BG2_XDX = 1 << 8;
BG2_XDY = 0;
BG2_YDX = 0;
BG2_YDY = 1 << 8;
BG2_CX = 0;
BG2_CY = 32 << 8;
dmaCopy(NormalBitmap_bin, (u16*)(BG_BMP_RAM(16)), 256*256);
videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(31,31,31);
BG_PALETTE_SUB[0] = RGB15(0,0,0);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
while(1)
{
scanKeys();
if (keysHeld() & KEY_UP)
{
//videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(16) | BG_PRIORITY(0);
iprintf("BG2 : front ?\n");
}
if (keysHeld() & KEY_DOWN)
{
//videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(16) | BG_PRIORITY(3);
iprintf("BG2 : bottom?\n");
}
swiWaitForVBlank();
} |
#115719 - nio101 - Thu Jan 18, 2007 6:02 pm
I did some tests and it seems that the priority stuff works in my configuration only with images stored on BG_BMP_BASE(X) with X < 16, even if I have 24x 16k that are allocated to MAIN_BG (VRAM_A, B & D)...
I don't know why but if someone can help...
thanks.
#115739 - strager - Thu Jan 18, 2007 9:20 pm
In your loop, you are setting BG2's priority to either 3 or 0. BG3's priority is always 3. If BG3's priority is 3, BG0-BG2 (and sprites) will be displayed over it. This is because BG's have relative priorities depending on their number. They function just like the standard priorities. BG3 has a relative priority of 3, and BG2 has a relative priority of 2 (for example). Since layeres of higher priorities are displayed "further back," BG2 is in front of BG3. The relative priorities are overridden by the BG's set priority.
A simple solution to your problem is to set BG3's priority to 2. That way, if BG2's priority is 0, it will be displayed in front of BG3. If BG2's priority is 3, it will be displayed behind BG3.
I hope this is somewhat clear. I'm not sure I understand my explanation myself.
#115764 - HyperHacker - Fri Jan 19, 2007 12:12 am
So what you're saying is if all four backgrounds are set to the same priority, BG3 > BG2 > BG1 > BG0?
_________________
I'm a PSP hacker now, but I still <3 DS.
#115776 - strager - Fri Jan 19, 2007 1:10 am
HyperHacker wrote: |
So what you're saying is if all four backgrounds are set to the same priority, BG3 > BG2 > BG1 > BG0? |
In the order of drawing, yes.
Since the higher priority backgrounds are drawn first, and the lower priority backgrounds after them, the lower priority backgrounds are shown in front of the higher priority backgrounds, because that BG only cares for its own transparency mask.
So, if all four backgrounds have the same priority, BG0 will be displayed closes to the viewer (in the front), followed by BG1, BG2, and BG3.
Though I could be completely wrong on this.
#115817 - nio101 - Fri Jan 19, 2007 9:34 am
I managed to keep my largebitmap on 512x384 instead of 512x512, and that allowed me to use some blocks of VRAMA+VRAMB to hold my second background... In this case, the priority switch is working perfectly...
Thanks for your answers...