Homebrew Garbage on top of screen when displaying text over background

Wolfgange

Well-Known Member
OP
Member
Joined
Feb 9, 2012
Messages
231
Trophies
1
XP
248
Country
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)
 

Attachments

  • Garbage_Error.zip
    315.7 KB · Views: 230

KazoWAR

Well-Known Member
Member
Joined
Aug 12, 2008
Messages
1,952
Trophies
1
Age
35
Location
Winter Haven
XP
2,130
Country
United States
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.
 
  • Like
Reactions: Wolfgange

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,851
Country
Poland
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.
 
  • Like
Reactions: Wolfgange

Wolfgange

Well-Known Member
OP
Member
Joined
Feb 9, 2012
Messages
231
Trophies
1
XP
248
Country
United States
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 or the font you were trying to use was improperly sized.
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!!!!!!!
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,851
Country
Poland
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?).

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.
 
  • Like
Reactions: Wolfgange

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: By the power of Florida Man, I have the power!!! *Lifts up meth pipe* Meth Man!!! lol