Skip to main content
gamedev.net
🔒 Locked

win32 double buffering???

Started by baddrizz Jan 15, 2002 at 9:04 PM 7 replies 1.4k views
Original Post
baddrizz
baddrizz
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
Brannon
Brannon
What are you using to draw with?

DirectDraw?
GDI?
OpenGL?
Something else? (what else is there?)


-Brannon
-Brannon
LNK2001
LNK2001
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
"-1 x -1 = +1 is stupid and evil."-- Gene Ray
Promit
Promit
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.)
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
DigitalDelusion
DigitalDelusion
Or you could do it using Get Set and ChoosePixelFormat...
look them up in MSDN and youll see what you need.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
LNK2001
LNK2001
quote:
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...
"-1 x -1 = +1 is stupid and evil."-- Gene Ray
baddrizz
baddrizz
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



PIXELFORMATDESCRIPTOR pfd;

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

pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_GDI | PFD_DOUBLEBUFFER;
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
UnshavenBastard
UnshavenBastard
quote:
Original post by Brannon
What are you using to draw with?

DirectDraw?
GDI?
OpenGL?
Something else? (what else is there?)


-Brannon



Can I access graphics memory directly with OpenGL, like
with dds->Lock() in DDraw? (pixels)


Drizzt DoUrden
Drizzt DoUrden
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 - (www.libsdl.org)
Cone3D Tutorials- (cone3D.gamedev.net)
GameDev.net''s Tutorials - (Here)

OpenGL:

Main Site - (www.opengl.org)
NeHe Tutorials - (nehe.gamedev.net)
Online Books - (Red Book) (Blue Book)
------------------------------Put THAT in your smoke and pipe it

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.