Difference between SDL_Update_Rect and SDL_Flip

Started by
2 comments, last by Arbel 16 years, 1 month ago
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.
Advertisement
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. =)

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.
Awesome, thanks for the answers. Makes a lot more sense.

This topic is closed to new replies.

Advertisement