Jump to content
  • Advertisement
Sign in to follow this  
clashie

GDI / DIB flickering

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

I'm new to GDI, and programming in general so bare with me here. Originally it was simply a starfield, which used SetPixel to draw the pixels. Obviously, this was horrifyingly slow. When I drew a lot of stars, it would CRAWL. I read that using a bitmap would be faster, and MSDN recommended that I use DIB's for the job. Needless to say, the speed gain was enormous, it went from probably what was single digit FPS to smooth, however during this transition, I seem to have goofed something as I get flickering. Excuse my stupid backround in the example, "Team BONER" is the gimmick I always release my stuff under, heh. I'd like if someone could check this, and tell me if they notice something obvious or have any suggestions. Link to source and example: http://dykebeard.drinkhound.com/porn/starfield.rar

Share this post


Link to post
Share on other sites
Advertisement
You might want to change the way your message loop is. It just sits there waiting for a message, this time could be used for real-time stuff.

so instead of this

while(GetMessage(&msg, NULL, 0, 0) > 0){
TranslateMessage(&msg);
DispatchMessage(&msg);
}




try this instead


MSG msg = { 0 }; // set the structure to 0

while( 1 )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT )
break;

TranslateMessage( &msg );
DispatchMessage( &msg );
} // end PeekMessage
else
{
// do real-time right here
}
}


Share this post


Link to post
Share on other sites
You probably need to double-buffer your bitmap surface. Also, don't waste cycled erasing or redrawing the windows background, just set the background to null and don't redraw the background later.

Also, its worth noting that once you get rid of the flicker there is, unfortunately, no way to get rid of the tearing you might well see. The only way around this that I've seen involved writing a small driver to monitor the vsync and hooking the application into it -- which works, but its an awful lot of hassle.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ravyne
You probably need to double-buffer your bitmap surface. Also, don't waste cycled erasing or redrawing the windows background, just set the background to null and don't redraw the background later.

Also, its worth noting that once you get rid of the flicker there is, unfortunately, no way to get rid of the tearing you might well see. The only way around this that I've seen involved writing a small driver to monitor the vsync and hooking the application into it -- which works, but its an awful lot of hassle.


Edit: Yeah, I'm a dolt and didn't fully understand double buffering. I found a good example and behold, it was exactly what I needed.

Thank you!

[Edited by - clashie on June 13, 2008 10:43:53 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!