When I run my application it reports 60 frames per second no matter what. At the moment it only renders a rectangle (from two triangles combined). I assume SDL automatically syncs with my monitor’s refresh rate of 60Hz to achive that low FPS count with such a simple scene.
Now if I call SDL_GL_SetSwapInterval(0); before I enter my game loop, I get around 4500 frames per second, but all 8 cores of my CPU sits at 100%. Obviously not good.
Out of curiocity I want the FPS count to be higher than 60, but not at the cost of 100% CPU usage. I then had a read in the SDL documentation and played around with a few things.
I noticed that if I call SDL_GL_SetSwapInterval(0); as before (let it render as soon as possible) - before I enter my game loop, then as the last call in my game loop (after I updated the screen), I call SDL_Sleep(2); then I get around 460 frames per second with 1-2% CPU usage. This seems pretty good, and more of what I wanted to achive. But then, thinking about it, I’m stealing 2ms (doing nothing) from my game loop. Now considering you only have ~33.3 milliseconds to achive 30FPS , or even worse ~16.6 milliseconds to achive 60FPS. 2ms (doing nothing) out of the latter is a bit worrying - and very expensive!
But is this the correct way to do things to get more that 60 FPS ,with still low CPU usage?