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 > Using 2D+3D hardware together on one screen?

#69720 - Extreme Coder - Wed Feb 01, 2006 2:57 pm

Hello.
I was trying to use the 2d (tiles+pals+sprites), with the 3d OGL hardware on the same screen. But only the 3d stuff appears. Here's the code I do for initalizing:
Code:

   // Turn on everything
   powerON(POWER_ALL);
   
   // Setup the Main screen for 3D
   videoSetMode(MODE_0_3D|DISPLAY_BG1_ACTIVE);
   vramSetBankA(VRAM_A_TEXTURE);                        //NEW  must set up some memory for textures
   vramSetBankB(VRAM_B_TEXTURE);                        //NEW  must set up some memory
   //vramSetBankC(VRAM_C_TEXTURE);                        //NEW  must set up some memory
   vramSetBankC(VRAM_C_MAIN_BG);
   //gluLookAt(10.0f, 8.0f, 20.0f, 10.0f, 8.0f, 0.0f, 0.0f, 1.0f, 0.0f);
   BG0_CR |= BG_PRIORITY(1);
   BG1_CR = BG_MAP_BASE(31)|BG_PRIORITY(0);
   
   BG_PALETTE[255] = RGB15(31,31,31);   //by default font will be rendered with color 255
   
   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);
   
   // IRQ basic setup
   irqInit();
   irqSet(IRQ_VBLANK, 0);

   // Set our viewport to be the same size as the screen
   glViewPort(0,0,255,191);
   
   // Specify the Clear Color and Depth
   glClearColor(0,0,0);
   glClearDepth(0x7FFF);


I tried different priorites, btw.

Thanx for the help in Advance.

#69728 - Dark Knight ez - Wed Feb 01, 2006 3:44 pm

First of all, I'm only now starting to look into pieces of code with OpenGL and NintendoDS, so what I'm about to say could not be accurate.... it's just a guess.

Could it be that the function glClearColor makes the background black on top of your 2D background? Meaning the 2D BG is there, but the 3D "blackness" is shown on top of that. What happens if you comment that out?

#69736 - Extreme Coder - Wed Feb 01, 2006 4:35 pm

glClearColor is only called first frame.

#69751 - ecurtz - Wed Feb 01, 2006 5:56 pm

It does work.

The dual pass demo I posted does an ugly hack with showing the 3D every frame but hiding it behind a BG layer on odd frames, so you could check that.

I'm still at the stage of the 2d/3d interaction being voodoo - I just curse and try changing everything until it does what I expect.

#69765 - Extreme Coder - Wed Feb 01, 2006 6:41 pm

What is supposed to work?
I'll check your demo now.
TNX
EDIT:I've checked your demo, I don't see what have I done wrong in the code above.Mind correcting my stupidity?:P

#69827 - ecurtz - Thu Feb 02, 2006 7:02 am

Sorry I just meant that using the BG layers along with the 3d output works.

My best guess is that glClearColor() call is messing you up because it always makes it opaque, try directly setting the value of the GFX_CLEAR_COLOR register to something (like 0).

I don't see anything else obvious there, but a couple other things to try.
Make sure there's stuff in the BG - fill it with random junk or something.
Turn up the alpha on the 3d layer and see if you see the bg through it.

#69857 - Extreme Coder - Thu Feb 02, 2006 12:17 pm

Thanks ecurtz, I fixed it. But the reason was very very wierd...
I just changed vram_main_bg to vram_main_bg_0x060000. I don't know what is the difference...

#69927 - Cthulhu32 - Fri Feb 03, 2006 12:50 am

you might also want to read up on what mode you're in. Remember there are multiple 3D modes, for my 2D/3D example I used Mode_5_3D.

so, videoSetMode(MODE_0_3D|DISPLAY_BG1_ACTIVE); would be videoSetMode(MODE_5_3D|DISPLAY_BG1_ACTIVE); Then you'd access your background just like you would with a Mode 5 bg.

#69952 - Extreme Coder - Fri Feb 03, 2006 6:27 am

Cthulhu32 wrote:
you might also want to read up on what mode you're in. Remember there are multiple 3D modes, for my 2D/3D example I used Mode_5_3D.

so, videoSetMode(MODE_0_3D|DISPLAY_BG1_ACTIVE); would be videoSetMode(MODE_5_3D|DISPLAY_BG1_ACTIVE); Then you'd access your background just like you would with a Mode 5 bg.


access which BG? The 3d BG(BG0)?