# GDI / DIB flickering

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

## 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 on other sites
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.

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

MSG msg = { 0 };  // set the structure to 0while( 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 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 on other sites
Quote:
 Original post by RavyneYou 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]

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999965
×