I was wondering if there is a frame rate cap built into SDL 2.0? If so, how could one modify the default cap?
I am creating a game engine using C++ and SDL 2.0. When I display what I believe to be the frame rate as rendered text onto the screen, the displayed result constantly fluctuates between 58 and 62 frames per second.
This seems odd to me as no matter how many images I render on the screen, or how much logic code work I put into a single cycle, the displayed frame rate remains within 58 to 62 frames per second.
Here is how I am calculating the frame rate:
// FPS
//Record the current system ticks
mSystemTicksCurrent = Timer::GetSystemTicks();
//Calculate the time it takes for a single cycle to run
mSingleCycle = mSystemTicksCurrent - mSystemTicksPrevious;
//to prevent division by zero...
if(mSingleCycle != 0)
{
mFPS = 1000.0f / mSingleCycle;
}
//...indicate that a miniscule amount of time has elapsed, thus leading to an extremely fast frame rate
else
{
mFPS = 9999.9f;
}
//Since we are done calculating the time it has taken for a single cycle to elapse,
//record the time that was used to calculate the elapsed cycle time for future use.
mSystemTicksPrevious = mSystemTicksCurrent;
and now I take the calculated frame rate and render it to the screen:
if(mpTimerFPS != nullptr)
{
if(mpTimerFPSText != nullptr)
{
sprintf_s(mTimerFPSTextBuff, "FPS: %.1f", mFPS);
mpTimerFPSText->SetTexture(Window::UpdateText(mTimerFPSTextBuff, mpTimerFPSFont, mTimerFPSColor));
}
}
Where the Timer::GetSystemTicks() function is simply as follows:
Uint32 Timer::GetSystemTicks()
{
return timeGetTime();
}
I can provide more code if necessary.
timeGetTime()
is not precise. It's precision on Windows is usually around 16 ms, which would give up to 62 FPS. – Collin DauphineeSDL_RENDERER_PRESENTVSYNC
flag ? wiki.libsdl.org/… – olevegard