Jump to content
  • Advertisement
Sign in to follow this  

Possible to eliminate flickering in GDI?

This topic is 4062 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

Hi, I've created several games using Windows GDI, and can't help notice that my sprite s flicker most of the time. Are there any ways in which I could eliminate flickering in GDI? Thanks in advance, - dadads -

Share this post

Link to post
Share on other sites
You can use a backbuffer. A backbuffer is an offscreen buffer, with the same dimensions as the window you are drawing to. Then, instead of drawing directly to the window, you draw everything in the backbuffer. When you have drawn everything and want to display it on screen, you simple copy the backbuffer to the window with BitBlt.

To create the backbuffer you simple do:

RECT rect;
GetClientRect( hwnd,&rect );
HDC windowdc = GetDC( hwnd );
HDC backbufferdc = CreateCompatibleDC( windowdc );
HBITMAP backbuffer = CreateCompatibleBitmap( windowdc, rect.right, rect.bottom );
HBITMAP oldbitmap = SelectObject( backbufferdc, backbuffer );
ReleaseDC( windowdc );

Now you can use backbufferdc instead of the window's device context.

NOTE: According to my interpretation of the MSDN, you need to do SelectObject(backbufferdc,oldbitmap); when you are finished with the backbuffer and wants to clean up. That's why we save oldbitmap above.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!