Drawing an image on subscreen of nds

坚强是说给别人听的谎言 提交于 2019-12-10 15:18:24

问题


I am totally new to libdns. I try to change the sample Graphics\Backgrounds\256_color_bmp to display the background on the subscreen.

Here is my code. Do you have any idea what is missing to display hey_typBitmap on the subscreen? I 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;
}

回答1:


In mode 5 the DS has 3 background layers available, and calling bgInit with 2 returns a reference to a different layer on the same screen. If you want to use a layer on the sub-screen, use bgInitSub.

There are 2 palettes too; one on the main screen and a different one on the sub-screen. The sub-screen palette is at BG_PALETTE_SUB.

Hopefully this code will show the image on the second screen (changes 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;
}


来源:https://stackoverflow.com/questions/5410762/drawing-an-image-on-subscreen-of-nds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!