Sign in to follow this  
Arbel

Difference between SDL_Update_Rect and SDL_Flip

Recommended Posts

Arbel    122
I've used both for animating in order to get rid of flicker. However, I'm confused on what is the actual difference. Both require the surface of the screen and update it. Which one is more efficient, and what exactly are they doing behind the scene? Ive read the documentation, but was hoping someone could give me a better explanation.

Share this post


Link to post
Share on other sites
signal_    366
So SDL_Update_Rect is easy to understand; it just updates a specified portion of the screen to display the most up-to-date graphical output.

SDL_Flip is for double buffering. To quote from some web page (too lazy to cite):

"One attribute virtually every game needs is double buffering. When you use double buffering, drawing is done in an offscreen buffer and the image is moved from the offscreen buffer to the screen."

So when one invokes SDL_Flip, an image is stored in a buffer and when ready and necessary it replaces the currently displayed image. From what I understand, this results in a smoother, less flickering display.

The case of SDL_Flip reduces to SDL_Update_Rect when double-buffering is not supported or enabled. So, in this case, SDL_Flip will 'swap' images with itself, yielding a refreshed image: equivalent to calling SDL_Update_Rect. I think then that there will be no difference between efficiency in this degenerate case.

Hopefully this helps. Although I love SDL and appreciate how easy it is to use, I think the documentation could be more robust. But, maybe I am just an idiot and need to be spoon-fed. =)

Share this post


Link to post
Share on other sites
Simian Man    1022
signal_ is right. Basically if you are using SDL in hardware mode, you should use double buffering and therefore SDL_Flip. If you are using SDL in software mode, you can't use double buffering and only need SDL_Update_Rect. To be safe, you can just call SDL_Flip in either case and it will sort it out.

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