SDL_Flip()

Started by
2 comments, last by jsloan 19 years, 7 months ago
HI there, Does anybody know how exactly the SDL_Flip() fucntion works? I read the doumentation but it was a bit unclear. If i blit to my back buffer 'pBack' would i call SDL_Flip(pBack) or SDL_Flip(pPrimary) for the primary surface? And if not how does SDL_Flip know which surface is what without the nifty surface descriptor stuff from directdraw?
Advertisement
With SDL double buffering, there's no need to create a separate back buffer. SDL does all that internally.

When you created the surface for the actual screen, I'm assuming you used the function call SDL_SetVideoMode(width, height, bpp, flags). If you pass SDL_DOUBLEBUF as the third parameter, SDL will allocate a back buffer for it.

Then when you draw to the screen, you blit to the surface as usual. You will actually be blitting to the back buffer, but SDL takes care of this. Then call SDL_Flip on the same surface, and it'll swap the back buffer with the surface you're updating.

A better explanation of using SetVideoMode and double buffering.
The only screen surface you need to concern yourself with is the one returned by SDL_SetVideoMode(), SDL will handle the details of the back buffer internally.

So if you have:

SDL_Surface *Screen = SDL_SetVideoMode(blah);//some drawing code hereSDL_Flip(Screen);


That's all you need, of course if you want to get really dirty you could look at the implementation of SDL_Flip() in the source code.
Thanks guys for clearing that up!

This topic is closed to new replies.

Advertisement