Advertisement

Flickering with GDI

Started by January 21, 2001 11:00 AM
5 comments, last by CTRL_ALT_DELETE 24 years ago
I am trying to make a pong clone with the Widnows GDI. It all works great, but there is a lot of flickering when the paddles move. Basiclly, When ever a up or down key is pressed, it changes a global variable. There are if statments in my main game loop to see if the paddle should be moved if it should be moved, I draw a black rectangle over it. Before the main game function exists, I redraw the paddles. I do know if this enough for any one to make suggestions, but i figured it was worth a shot.
Join the club, hehe My pong is EXACTLY the same as you said, same problem...
Peon
Advertisement
Your problem might be that you are not using a back buffer. If your not, what you need to do is call CreateCompatibleDC in order to create a place to hold the off screen buffer. Then call CreateCompatibleBitmap to make the buffer. Next, use SelectObject in order to select the HBITMAP you created into the HDC you created with CreateCompatibleDC.

Once you have done all of this, do all of your screen redrawing in the buffer you created. Once you''ve finsihed the frame copy the buffer to the screen using BitBlt. The key to no flickering is NOT to erase what is on the screen, but rather just draw ontop of it; so, if you''re using Invalidate rect make sure that the parameter that says to erase the background is false.

Maybe this will help you out.
LOL! I''ve been erasing ever since QB, could never get rid of that annoying flicker! Well that explains it, hehe I''m moving into DirectX, so I''ll make sure to fix my errors.

Thanks a lot!

Peon
Peon
Thanks for your reply Mike. No I am not using a back buffer and I will do some reading on the functions you mentioned. thanks!
If you have trouble figuring out how to get things to work just email at Mike010@netZero.net and I can provide you with source code to help you out.
Advertisement
You can still get around the flickering by waiting for the vertical sync...yes you can do it in windows too!

Look up vsync in the old dos docs on this site and you should find something.

GL! =)

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

This topic is closed to new replies.

Advertisement