Garbage on top of screen when displaying text over background

Discussion in 'NDS - Emulation and Homebrew' started by Wolfgange, Jul 10, 2013.

  1. Wolfgange
    OP

    Wolfgange GBAtemp Regular

    Member
    224
    84
    Feb 9, 2012
    United States
    I asked this same question on the devkit pro forums, but the posts dont seem to be going through.

    Another newb question..

    I am currently using the 16-bit libnds example as a basis and am trying to display text and the png background image on the same screen (in this example it is the top sceen). I am having a similar issue as this post:
    http://devkitpro.org/viewtopic.php?f=6&t=3222&hilit=background and text

    I have garbage on the top of the screen (only if consoleInit(...) is called), similar to the first problem in the thread. The only problem is that I am displaying the background image in a different method so the fixes they made in that thread did not apply to this.

    All I am looking for is whether there is a way to fix the garbage on the top of the screen. If there is a more efficient/better way to do display the image, I am willing to accept it, just I haven't found a detailed enough tutorial on how to load an image as a background without using this method. Thank you in advanced for any help whatsoever.

    (The project is attached)
     

    Attached Files:

  2. Wolfgange
    OP

    Wolfgange GBAtemp Regular

    Member
    224
    84
    Feb 9, 2012
    United States
    Does anyone know of just how to display 256x192 pngs using dmaCopy?
     
  3. Wolfgange
    OP

    Wolfgange GBAtemp Regular

    Member
    224
    84
    Feb 9, 2012
    United States
    Anyone at all?
     
  4. KazoWAR

    KazoWAR GBAtemp Advanced Maniac

    Member
    1,799
    681
    Aug 12, 2008
    United States
    Winter Haven
    i tried looking at it but i am not sure how to fix it. i know the problem, when you init the console the graphic data for the characters is overwriting the top of the image, since its a 4bpp data and not 16bpp it looks like random garbage in 16bpp mode. the solution is the same as in the tread, the are using the same memory and you need to move one of them elsewhere, but i dont know how to do that with a 16bit image.
     
    Wolfgange likes this.
  5. Wolfgange
    OP

    Wolfgange GBAtemp Regular

    Member
    224
    84
    Feb 9, 2012
    United States
    Thanks for giving effort into this:).
     
  6. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,536
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    You really don't want to display .PNG's on the DS - you're far better off using native raster images or tiled backgrounds. The project you attached doesn't actually display a .PNG file, the image goes through GRIT conversion.

    My suggestion is to download a copy of WINGRIT, converting your backgrounds and attaching them to your project that way rather than relying on convoluted makefiles. Yeah, I know it automates things, but "my way" lets you choose the more intricate options when it comes to converting.

    As for the jumbled text, I'm guessing that the area of VRAM you were trying to use was already occupied, you were trying to output tiled text to a layer which does not support it in the selected MODE or the font you were trying to use was improperly sized.

    Can't tell for sure as I haven't looked into the source yet, I'm kinda in a hurry right now. :P

    EDIT: Yep, it's a memory overlap. Gimme a sec, I'll try to find a tilebase/mapbase calculator I used to use.

    EDIT2: Got it, perfect!
    http://mtheall.com/vram.html

    Use this tool to properly allocate your memory in VRAM.

    You can also check out my DS programming tutorial here:
    http://gbatemp.net/threads/ds-programming-for-newbies.322106/

    It's not strictly for libnds, but it will teach you the bare basics as well as introduce you to NightFox Lib which will deal with such issues for you automatically.
     
    Wolfgange likes this.
  7. Wolfgange
    OP

    Wolfgange GBAtemp Regular

    Member
    224
    84
    Feb 9, 2012
    United States
    Thank you very much for the response, and wingrit seems like a plausible alternative. The only thing is I still don't understand how to load in the tiled background (as in, is there any tutorial that would help me at all?).

    EDIT: THANKS SO MUCH!!!!!!!
     
  8. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,536
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    Loading Tiled Backgrounds is very easy.

    Code:
        videoSetMode(MODE_0_2D);  //Set Video Mode
        vramSetBankA(VRAM_A_MAIN_BG);  //Assign VRAM Bank
     
        int bg = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0,1); //Init a Background
     
        dmaCopy(TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));  //dmaCopy Tiles data
        dmaCopy(Layer256x256Map, bgGetMapPtr(bg),  Layer256x256MapLen);  //dmaCopy the Map
        dmaCopy(TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));  //dmaCopy the Palette
     
        scroll(bg, 256, 256); //Scroll the background to the desired position
    This is really all there is to it - GRIT does the rest for you.

    This example code (minus my comments) can be found in your devkitPro folder under Examples/Graphics/Backgrounds/All_in_One which show all of the Tiled Background types you can use.
     
    Wolfgange likes this.