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 > HUD

#164729 - iainprice - Sun Nov 16, 2008 12:19 pm

I'm about to release version 1 of my FPS based on my terrain viewer.....

I want a HUD, can someone explain how I setup my layers so that I can display an image overtop of my 3D view.

I think the devkitpro examples are very useful but there doesn't seem to be anything for 2D image over 3D drawing....please point me to it, if I'm wrong :)

Thanks for your help, my FPS will be called Renegade....will post it soon :)

#164730 - Ludo6431 - Sun Nov 16, 2008 1:53 pm

The 3D layer is in the BG0 so put BG0 with a higher priority than BG3 (by exemple) and draw on your BG3.

#164731 - iainprice - Sun Nov 16, 2008 6:36 pm

sorry to sound silly but how do i set priority levels? I can set both to active...


|BG_PRIORITY_0

when i set it active?

#164733 - Ludo6431 - Sun Nov 16, 2008 7:10 pm

You don't sound silly ;)
Everyone have to learn ;)

You can do something like this :
Code:
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
// ...
BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE(6) | BG_PRIORITY(2);

The BG2 will be ontop of the BG3.

#164734 - iainprice - Sun Nov 16, 2008 8:13 pm

Hmmmmm

I have tried:

[code]
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | MODE_5_3D);
BG3_CR = BG_BMP16_256x256 | BG_PRIORITY(1);
[/code]

but the mode_5_3d just stamps over the image.... without it the image is shown, with it the 3d is shown, how do i set the priority of the 3d lower than the 2d?

#164735 - Cearn - Sun Nov 16, 2008 9:24 pm

iainprice wrote:
Hmmmmm

I have tried:
Code:
videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | MODE_5_3D);
BG3_CR = BG_BMP16_256x256 | BG_PRIORITY(1);

but the mode_5_3d just stamps over the image.... without it the image is shown, with it the 3d is shown, how do i set the priority of the 3d lower than the 2d?

It might help to look up REG_DISPCNT in GBAtek (and perhaps REG_BGxCNT too (where x is 0 through 3)) to understand what's going on here. The REG_DISPCNT register controls the main display settings, with different bitfields being used for different capabilities. videoSetMode( ) just puts a value into this register. As it happens, there are no separate modes for 2D and 3D; MODE_x_3D is the same as MODE_x_2D except that an additional bit is set that indicates BG0 is 3D and not 2D and auto-enables BG 0.

Code:
// From libnds/include/arm9/video.h:

#define MODE_5_2D      0x10005

...

#define MODE_5_3D    (MODE_5_2D | DISPLAY_BG0_ACTIVE | ENABLE_3D)


As for background priorities, these are again also just a bitfield in a control register, in this case REG_BGxCNT. There are four priority settings, but these are actually independent of the background number.

By default, all priorities are 0. Even if you set your 2D image's background to priority 1, the 3D background (i.e, BG0) is still set to 0. Since the priority marks the 'depth', the 3D BG will appear over the 2D one. If you want the 3D behind something, you need to set its priority to a higher number, not those of the others.

Code:
REG_BG0CNT= BG_PRIORITY(3);

// set REG_BG3CNT to anything except BG_PRIORITY(3).
// For clarity, also always set the TILE/MAP/BMP bases explicitly,
// even if they are 0.
REG_BG3CNT = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(0);


iainprice wrote:
I think the devkitpro examples are very useful but there doesn't seem to be anything for 2D image over 3D drawing....please point me to it, if I'm wrong :)
There is. Go to examples\nds\Graphics\3D\Misc\Mixed_Text_3D.

#164736 - iainprice - Sun Nov 16, 2008 10:52 pm

Thanks for your help.... getting there, it's working on ideas emu but not on my R4... hmmmmm

few more cups of coffee and i'm sure it will work.

#164747 - Echo49 - Mon Nov 17, 2008 5:47 am

I would make sure you're initializing everything explicitly. I recently discovered that No$gba (2.6 I think) has the GL_BLEND bit set by default, so although I got everything working the way I wanted on the emulator, it didn't work on the DS until I explicity set that bit.

#164751 - elhobbs - Mon Nov 17, 2008 9:42 am

iainprice wrote:
Hmmmmm

I have tried:

Code:

videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | MODE_5_3D);
BG3_CR = BG_BMP16_256x256 | BG_PRIORITY(1);


but the mode_5_3d just stamps over the image.... without it the image is shown, with it the 3d is shown, how do i set the priority of the 3d lower than the 2d?
you have the priorities reversed. 0 being the highest priority it will draw over everything. or, you could also think of it as the ds layers them in reverese order - largest number to lowest number, with the lower numbers over-writing the higher numbers.
Code:

videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | MODE_5_3D);
BG3_CR = BG_BMP16_256x256;
BG0_CR |= BG_PRIORITY(1);
any pixels on BG3 that are 0 (I think it is really just the high bit clear) will allow BG0 to show through.

also, using a 16bit background is going to use a lot of texture memory. you may want to consider using an 8bit background at some point. it is not without it's issues though since the vram cannot be written to using 8bit writes.

#164753 - iainprice - Mon Nov 17, 2008 10:50 pm

As i was using BG0 and BG3, I needed to set the priority for BG1 and 2 too....

All working, thank you for your help..... oh yeah and thanks for pointing me to a useful example.....