# SDL2 and frames per second

I'm diving into the world of SDL2 and C++ and have a few questions after my first few weeks in. Seems like a lot of the tutorials are (from what I understand) limiting the frames per second with a formula that uses the SDL_GetTicks() function to calculate current and last ticks and setting it back, as to limit the frames per second. I could be wording that wrong. Anyways, I've learned about the SDL_RENDER_PRESENTVSYNC flag for SDL_CreateRenderer() and according to fraps it seems to be working quite nicely and locking my FPS at 60 (instaed of 2000+).

My question is, Is SDL_RENDER_PRESENTVSYNC enough to solve the issue or should I also be using that common formula I've been seeing in many tutorials with all the SDL_GetTicks() stuff? Are both methods doing something different that I'm not aware of? I thought they were both just setting/limiting the FPS.

• "...enough to solve the issue..." You don't raise any issue. – Vaillancourt Feb 18 '16 at 13:09
• You could be interested in this article. – Vaillancourt Feb 18 '16 at 14:23

The synchronization with the VSync, like what you set with SDL_RENDERER_PRESENTVSYNC, is tied to the display of your game.

So it will be synchronized to the monitor refresh rate.

If you solely rely on this to throttle your frame rate, you could run into this kind of issues:

• Visual issues when using multiple monitors
• Different smoothness across multiple devices (i.e. if you run your game on an Oculus Rift, which has a much higher refresh rate, your game will appear smoother than what you'll see on a computer monitor, on a slow phone device)
• Potential lag issues: if your 'update' takes more time than the time between 2 screen refresh, chances are that the frame will wait until the next refresh to update (this is truly an horrible experience)

This is only to show you why you should throttle the frame-rate yourself with one of the other methods that you've seen.

• Excellent advise. I'll rely less on SDL_RENDER_PRESENTVSYNC and learn more about the other ways to manage frame rates. Thank you. – GunnDawg Feb 18 '16 at 14:22