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


win32 double buffering???

Recommended Posts

i know this isn''t dx related but as far as i can tell this part of the board gets the most posts newbie here i was wondering how you make a double buffering system in win32 cause i''m making a simple game and would like to get ride of the flicker thx for any help

Share this post

Link to post
Share on other sites
Brannon: Don't forget GDI+.

baddrizz: (Assuming you're using GDI)

At every WM_PAINT event, do:

1. Create an bitmap with CreateCompatibleBitmap()
2. Create an off-screen DC with CreateCompatibleDC()
3. Select the bitmap into the off-screen DC with SelectObject()
4. Do all your drawing on the off-screen DC
5. Blit the off-screen DC onto your window's DC with BitBlt()
6. Deselect the bitmap from the off-screen DC (SelectObject())
7. Delete the off-screen DC (DeleteDC())
8. Delete the bitmap (DeleteObject())

This is a pretty slow method, though. To optimize, you might want to create the bitmap and off-screen DC at startup (re-creating them on window resize) and delete them on shutdown.

If you're not using GDI, feel free ignore this post.

Edited by - LNK2001 on January 16, 2002 3:25:04 AM

Share this post

Link to post
Share on other sites
I, too, assume you r using GDI.

Create the bitmap and the off-screen HDC at startup. THis is analogous on your side to a D3D/DDraw backbuffer. Draw everything to the off-screen DC, then draw the entire off-screen DC to the on-screen DC.

For whatever reason, this tends to fail absolutely in VB. Not sure why. (something to do with AutoRedraw and other such VB drawing settings, not completely sure.)

Share this post

Link to post
Share on other sites
Original post by DigitalDelusion
Or you could do it using Get Set and ChoosePixelFormat...
look them up in MSDN and youll see what you need.

That was an interesting idea! I never thought of using ChoosePixelFormat() for anything other than OpenGL...

Share this post

Link to post
Share on other sites
thx for your replys sorry forgot to say i''m using the GDI i tried using PIXELFORMATDESCRIPOR(think its spelled right) here is how i set it up and i didn''t work


memset(&pfd, 0, sizeof(pfd));

pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;

UINT pixelformat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, pixelformat, &pfd);

and then called SwitchBuffer(hdc); after all the drawing was done and it didn''t change anythingi''m going to try the other idea''s right now.....
thx again

Share this post

Link to post
Share on other sites
I''m sorry to get off topic, but does your user name represent bad me? Like, BadDrizzt.

Or just drizz in some way.

Just wondering.

Simple DirectMedia Layer:

Main Site - (
Cone3D Tutorials- (''s Tutorials - (Here)


Main Site - (
NeHe Tutorials - (
Online Books - (Red Book) (Blue Book)

Share this post

Link to post
Share on other sites