Archived

This topic is now archived and is closed to further replies.

UeberBobo

double buffering

Recommended Posts

can anyone explain the concept of double buffering. got some tut off gametutorials but i cant get it to work when i try to implement it into my own code btw remember i am only three years old...

Share this post


Link to post
Share on other sites
There are two screens. One you can see and one you can''t. Print on the hidden (back) screen then swap the two. That way it looks like you have instantly printed everything on the front screen. That stops flicker.

For full screen the pointers are usually swapped so the speed to swap front and back screens is very fast. For windowed apps, the back screen is copied on to front like one big picture.

Mark

Share this post


Link to post
Share on other sites
<< got some tut off gametutorials but i cant get it to work >>

Got the same tutorial and got mine to work. You have a couple of things in addition to your standard hinstance, hwindow, hdc....

// variable declares for back buffering
HDC back_dc = NULL;
HBITMAP back_bmp = NULL;
HBITMAP old_bmp = NULL;
RECT back_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT};

// this is called in your GameInit
game_dc = GetDC(game_window); // get the GDI device context
// for back (double) buffering
back_dc = CreateCompatibleDC(game_dc);
back_bmp = CreateCompatibleBitmap(game_dc, WINDOW_WIDTH, WINDOW_HEIGHT);
old_bmp = (HBITMAP)SelectObject(back_dc, back_bmp);

// this is called in your GameMain
// erase the back buffer
FillRect(back_dc, &back_rect, black_brush);

// draw to back_dc etc...etc...

// copy back buffer to front buffer
BitBlt(game_dc, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, back_dc, 0, 0, SRCCOPY);

Here is the rest....

Back Buffer Demo


[edited by - PhilVaz on October 7, 2003 6:15:37 AM]

Share this post


Link to post
Share on other sites