gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > A few (hopefully) simple questions

#154648 - ZeroSum - Sat Apr 19, 2008 8:35 pm

I've been playing around with libnds a bit and currently have some questions. I might have answered some of them myself but I'd like some confirmation that I've understood some things properly. I don't have my DS at the moment so sorry if some are painfully obvious if I just tried changed the code ><

1) To change a background I've just been dmaCopy'ing a new background into the memory. Am I right that the DS will just constantly draw whatever is in the memory it's pointing to and there's no need to "unload" things or constantly redraw it (like after every frame on a PC)?

2) Every sprite tutorial I've read has used one image per sprite. I've got about ~100 sprites so I would like to use just a sprite "sheet", would the tile hardware let me do this? Would I have to space the sprites in the sheet image a certain way?

3) Can you change video modes and vram settings whenever you want? I suppose yes as long as you set everything up right after each change?

4) Out of interest, is it possible to use backgrounds, sprites and the frame buffer on the same screen at the same time? So I could pixel plot over the top if I wanted to?

5) How would I set up the console to draw over the top of other backgrounds? I use both screens for the game but would like to display the log over the top of one if a button is pressed but I'm unsure how initConsoleDefault works...

At the moment I setup the console like so:

Code:

// This sets the BG to use a certain tilemap? Is this a default character tilemap? Could I change the font by replacing this if I wanted?
SUB_BG0_CR = BG_MAP_BASE(31);

// Text is drawn using this palette colour.
BG_PALETTE_SUB[255] = RGB15(5,31,5);   

consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);


To draw the text over the top of the game I should set it to the topmost background I'm guessing, but would I need to change any of the parameters for consoleInitDefault()? What does the first and second parameter actually point to? If I wanted to display on the main screen can I just take out the _SUB parts?

Thanks for reading!

#154650 - josath - Sat Apr 19, 2008 8:57 pm

ZeroSum wrote:
1) To change a background I've just been dmaCopy'ing a new background into the memory. Am I right that the DS will just constantly draw whatever is in the memory it's pointing to and there's no need to "unload" things or constantly redraw it (like after every frame on a PC)?

Right... the DS gfx hardware just uses the data you feed it and draws it on the screen for you

Quote:
2) Every sprite tutorial I've read has used one image per sprite. I've got about ~100 sprites so I would like to use just a sprite "sheet", would the tile hardware let me do this? Would I have to space the sprites in the sheet image a certain way?

Read this tutorial on GBA sprites. DS sprites are almost exactly the same:
http://www.coranac.com/tonc/text/regobj.htm

In particular, see the parts about 1D and 2D mapping. 2D mapping seems to make more sense at first, but 1D mapping is usually a lot easier to implement & more efficient (no gaps in your VRAM)

Quote:
3) Can you change video modes and vram settings whenever you want? I suppose yes as long as you set everything up right after each change?

Yeah, you can pretty much change the settings whenever you want. Ideally though, you make the changes during VBLANK so that the screen doesn't flicker / tear.

Quote:
4) Out of interest, is it possible to use backgrounds, sprites and the frame buffer on the same screen at the same time? So I could pixel plot over the top if I wanted to?

Yes and no. You can use background and sprites at once, but not framebuffer mode. HOWEVER: You can have a 'bitmap' background which acts just like the framebuffer mode with a few more features. And you can change the priority of the backgrounds/sprites so some are on top/underneath/etc

#154657 - Cydrak - Sat Apr 19, 2008 11:52 pm

Quote:
4) Out of interest, is it possible to use backgrounds, sprites and the frame buffer on the same screen at the same time? So I could pixel plot over the top if I wanted to?

Worth noting is the DS' separation between display and rendering (only partial, since they're synchronized). Framebuffer is a display mode and it works by reading from VRAM, instead of the 2D layer engine. DISPLAY_CR:0-3 could be called a render mode: it controls behavior of the layers (tilemap or 3D on BG0, and affine toggles for BG2-3).

That's why you "can't" use framebuffer and BGs on the same screen.

It's a lot clearer when you look at the capture unit, which blends and writes to framebuffers. In that case, a framebuffer display makes perfect sense: it gives you motion blur, limited rendering offscreen, etc. Then you're using BG, OBJ and/or 3D indirectly, through the capture.

If you just want to plot though, then as josath said, a bitmap is much more flexible (you even get two of them).

Quote:
5) How would I set up the console to draw over the top of other backgrounds? I use both screens for the game but would like to display the log over the top of one if a button is pressed but I'm unsure how initConsoleDefault works...

This is a good question. consoleInitDefault(mapPtr, tilePtr, colors) does two things:
1) Copies the console font (256 tiles or 8KB) to *tilePtr. If colors != 16, the tiles will be 8-bit. In either case color 255 will be used.
2) Sets up the console, which will then draw text to *mapPtr.

The console never touches your BGs, so set them up however you like. All it needs is empty VRAM for a 32x32 map, some tiles, and a BG set up to use the memory you passed in. It doesn't even care which screen it's on, so you can remove the "SUB"s if you want.

#154724 - ZeroSum - Sun Apr 20, 2008 11:51 pm

Thank you for the replies and links. Makes a lot more sense now.