Jump to content
• Advertisement

# GDI / DIB flickering

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

##### 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 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 this 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

##### 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]

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
A4L
13
5. 5
• Advertisement

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013658
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!