Sign in to follow this  
dadads

Possible to eliminate flickering in GDI?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this