Drawing an image on the nds subscreen

I am completely new to libdns. I am trying to change the Graphics \ Backgrounds \ 256_color_bmp sample to display the background on a sub-screen.

Here is my code. Do you have an idea of ​​what is missing to display hey_typBitmap on a sub-screen? I have already managed to display the new image on the top screen.

#include <nds.h> #include <stdio.h> #include "drunkenlogo.h" #include "hey_typ.h" int main(void) { videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG_0x06200000); int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0); dmaCopy(hey_typBitmap, bgGetGfxPtr(bg3), 256*256); dmaCopy(hey_typPal, BG_PALETTE, 256*2); int bg2 = bgInit(2, BgType_Bmp8, BgSize_B8_256x256, 0,0); dmaCopy(drunkenlogoBitmap, bgGetGfxPtr(bg2), 256*256); dmaCopy(drunkenlogoPal, BG_PALETTE, 256*2); while(1)swiWaitForVBlank(); return 0; } 
+4
source share
1 answer

In mode 5, DS has 3 available background layers, and a call to bgInit with 2 returns a link to another layer on the same screen. If you want to use a layer on a secondary screen, use bgInitSub .

There are also two palettes; one on the main screen and the other on the secondary screen. The sub-screen palette is in BG_PALETTE_SUB .

I hope this code shows the image on the second screen (changes are marked with /* ! */ ):

 int main(void) { videoSetMode(MODE_5_2D); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); videoSetModeSub(MODE_5_2D); vramSetBankC(VRAM_C_SUB_BG_0x06200000); int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0); dmaCopy(hey_typBitmap, bgGetGfxPtr(bg3), 256*256); dmaCopy(hey_typPal, BG_PALETTE, 256*2); int bg3sub = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 0,0); /* ! */ dmaCopy(drunkenlogoBitmap, bgGetGfxPtr(bg3sub), 256*256); /* ! */ dmaCopy(drunkenlogoPal, BG_PALETTE_SUB, 256*2); /* ! */ while(1)swiWaitForVBlank(); return 0; } 
+2
source

Source: https://habr.com/ru/post/1344982/


All Articles