3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ "...enough to solve the issue..." You don't raise any issue. \$\endgroup\$ Commented Feb 18, 2016 at 13:09
  • \$\begingroup\$ You could be interested in this article. \$\endgroup\$ Commented Feb 18, 2016 at 14:23

1 Answer 1

4
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Excellent advise. I'll rely less on SDL_RENDER_PRESENTVSYNC and learn more about the other ways to manage frame rates. Thank you. \$\endgroup\$ Commented Feb 18, 2016 at 14:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.