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 > Graphic Problems

#152225 - ben0bi - Wed Mar 12, 2008 3:53 am

Hi,
I have some problems setting up the graphics properly:

i want to use 16bit direct draw.

Problems are the following:
- if i do NOT clear the Buffer, everything goes well. But the pixels are not deleted then...(moving stars demo)
- if i do clear the buffer, HALF of the screen will be blank.

- if i use doublebuffering, it WORKS - halfways.
(on the emulator everything is good, but on the real machine, the
half picture is darker than the other half.)

- if i set the doublebuffer memory into the main buffer memory, the darker screen will be drawn correct.

PLEASE help me, i really am frustrated, since 3 day i try to set up a SIMPLE background to draw to...(no framebuffer please..) - and how do i use one background over another, thats the next big question.

here is my source:

Code:


u16* g_pu16ActualDrawBuffer=NULL;
bool actualBuffer=0;

int main(void)
{
   // irqs are nice
   irqInit();
   irqSet(IRQ_VBLANK, 0);

   bool actualBuffer=0;

   videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
   vramSetBankA(VRAM_A_MAIN_BG_0x06000000);   
   initConsole();

   BG3_XDY = 0;
   BG3_XDX = 1 << 8;
   BG3_YDX = 0;
   BG3_YDY = 1 << 8;

   lcdMainOnBottom();

...

   while(1)
   {
      if(actualBuffer)
      {
         actualBuffer=false;
         gfxSetDrawBuffer((u16*)BG_BMP_RAM(0));
         BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(6);
      }else{
         actualBuffer=true;
         gfxSetDrawBuffer((u16*)BG_BMP_RAM(6));
         BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0);
      }
      
      gfxClear();
      swiWaitForVBlank();
...
                       gfxSetPixel(10,10,RGB15(31,0,0))
              }

}

Code:

void gfxClear(void)
{
   for(int i=0;i<256*256;i++)
      g_pu16ActualDrawBuffer[i]=RGB15(0,0,0)|BIT(15);
}

void gfxSetDrawBuffer(u16* newBuffer)
{
   g_pu16ActualDrawBuffer=newBuffer;
}

void gfxSetPixel(int pos,u16 color)
{
   if(g_pu16ActualDrawBuffer!=NULL)
   {
      g_pu16ActualDrawBuffer[pos]=color|BIT(15);
   }
}
Code:

void initConsole()
{
   videoSetModeSub(MODE_2_2D | DISPLAY_BG0_ACTIVE);
   vramSetBankC(VRAM_C_SUB_BG);
            SUB_BG0_CR = BG_MAP_BASE(31);
   BG_PALETTE_SUB[255] = RGB15(31,31,31);
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

   iprintf("\n\n\tBenoWorks Unlimited presents a DS game.\n");
}


thanks in advance.

#152277 - nce - Thu Mar 13, 2008 6:30 am

long time I haven't played with that (and no time to check BG_BMP_BASE stuff )but:

a 16bit buffer for the screen should take a complete vram bank. ( 256*256*2 = 128Ko )
If you want double buffer you need to set 2 vram bank... I guess.
( you are just setting bankA )

-jerome-
_________________
-jerome-

#152278 - Cydrak - Thu Mar 13, 2008 7:31 am

Bitmaps only need memory for what's shown, so for this case you need 256*192*16bit = 96kbyte per buffer. However, A still isn't enough for two...

Also, there's a limited amount of time to effect screen updates. You can't easily expect to clear and redraw the whole screen before end of vblank. Flicker, "tearing" and dropout is a sign the hardware caught up and shown your half-drawn image (probably mid-clear in your case). For double buffers this is no problem. Framerate may still suffer, drawing a whole game like this, but that's another story...