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.

Coding > Double buffering

#47629 - masterlodi - Mon Jul 11, 2005 4:04 pm

I'm trying to write a tron like game with a background.

I'm using Mode 4 with double buffering.

I've got this

Code:

DrawBackground();
PlotPixel( user_x, user_y, 0);
WaitForVblank();
Flip();


It draws the current drawing position fine but overwrites where the player has been.
How do I overcome this please?

#47637 - sajiimori - Mon Jul 11, 2005 5:29 pm

Does DrawBackground() overwrite the whole screen with the background? If that's not what you want, then don't do it.

#47683 - masterlodi - Tue Jul 12, 2005 9:03 am

I solved this by doing the following

Code:

int main()
{
  SetPalette();
  DrawBackground();
  SaveScreen();

  while(1)  // main loop
  {
    DrawSavedScreen();       
    PlotPixel( user_x, user_y, 0);
    WaitForVblank();
    Flip();
    SaveScreen();
  }
}

#47688 - Cearn - Tue Jul 12, 2005 12:17 pm

Remember the difference between double buffering and page flipping. Double buffering uses a separate buffer which is draw to and then copied to the display buffer. Page flipping uses two buffers (pages) and the simply switches between the two. Right now, you're using both at the same time, which is work, but is kind of redundant. Besides that, depending on the implementation of DrawSavedScreen() and SaveScreen(), double buffering may be very, very slow.

Assuming that PlotPixel alrady accounts for the bytes-vs-VRAM problem, what happens is that you write one pixel to one page, move, flip, then write the next frame to the other page. It's not overwriting, the pixel was never drawn in that frame in the first place. To fix that, write to both frames.
Or, since this is a laserbike game where you just add pixels but never really remove them except for starting a new game, just scrap the double buffering/page flipping altogether.

#47695 - masterlodi - Tue Jul 12, 2005 12:50 pm

Hi Cearn,

Thanks for clarifying the matter. I will drop the double buffering/page flipping!!

Thanks again!