Archived

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

Backbuffer in Win32 GDI

This topic is 5743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone simply explain to me how to do double buffering using the Windows GDI. I''ve looked around and there doesnt seem to be to much info on the subject. I''m planning on writing a simple windows game as quickly as possible and i don''t want to go through all the complexities of setting up and using direct draw.

Share this post


Link to post
Share on other sites
just create a bitmap (dib or otherwise, make sure its the same size as the window client area AND the same color depth as the screen) and draw everything to that. then after your set, blit that to the window dc. its that simple. there is no flipping with the gdi, and for the most part its up to the video vender to decide whether gdi apps have to blit to the screen on vsync, so dont worry about that either. and the gdi in windowed mode is quite fast (if done right, it can be as fast as directdraw in windowed mode).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Stephan Antonel
Cool thanx , but how do you draw to a bitmap.
I thought you used a DC for drawing.


Create an off-screen DC (see CreateCompatibleDC()), select the bitmap into it and do your drawing on the off-screen DC. And then BitBlt.

Share this post


Link to post
Share on other sites
I tried the method mentioned by apersonf using an offscreen dc and bliting a black rectangle to the screen everytime
. This works but extremely slowly and generates much flicker . Can anyone give me a tried and tested way to do graphics smoothly in windows and give some C code to back it up (not MFC because i haven''t learned it).

Share this post


Link to post
Share on other sites
quote:
Original post by Stephan Antonel
I tried the method mentioned by apersonf using an offscreen dc and bliting a black rectangle to the screen everytime
. This works but extremely slowly and generates much flicker . Can anyone give me a tried and tested way to do graphics smoothly in windows and give some C code to back it up (not MFC because i haven't learned it).


Check out this page: Windows 2000 Graphics API Black Book

Scroll down about 3/4 of the page, look for a title Using a Memory Device Context to Eliminate Flicker . Below that it lists off the steps involved in double buffering and provides a C++ example (no MFC) that can easily be devolved into C by changing the casting syntax. eg. change "static_cast(SelectObject(hDC, hPen));" into "(HPEN)SelectObject(hDC, hPen)"



[edited by - lessbread on March 24, 2002 6:19:19 PM]

Share this post


Link to post
Share on other sites