I use vsync in my program, and it works fine until I minimize the window. I did this when I created the renderer:
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
And here is the game loop:
while (running)
{
checkEvent();
handleKeyboard(timer.getDelta());
render();
}
It gives me a stable 60 frames per second, but I get more than 100000 frames per second when I minimize the window. Why is that happening?
Probably just a bug in SDL. If you investigated the problem more: read docs do some tests, you can report the bug. It is likely going to be fixed pretty soon. Ryan and colleagues work great. :)
That being said. I would never assume that Vsync works on every system. You probably want to add in your own framerate limitation system. Relying on the hardware to limit the framerate is a bad idea.
EDIT: I use this in my game to limit the framerate:
while (!gameLoop->done)
{
int start = SDL_GetTicks();
gameLoop->update();
int time = SDL_GetTicks() - start;
if (time < 0) continue; // if time is negative, the time probably overflew, so continue asap
int sleepTime = gameLoop->millisecondsForFrame - time;
if (sleepTime > 0)
{
SDL_Delay(sleepTime);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With