Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The frame rate limit itself is very simple. Outside the idle function, you need to contain a variable with the time of the last call to the idle function, and in the function itself, you just need to accumulate the frame rate delta and call glutPostRedisplay
.
double GetCurrentTime()
{
using Duration = std::chrono::duration<double>;
return std::chrono::duration_cast<Duration>(
std::chrono::high_resolution_clock::now().time_since_epoch()
).count();
}
const double frame_delay = 1.0 / 60.0; // 60 FPS
double last_render = 0;
void OnIdle()
{
const double current_time = GetCurrentTime();
if( ( current_time - last_render ) > frame_delay )
{
last_render = current_time;
glutPostRedisplay();
}
}
double
makes it easier to find the delta between frames and control the delta error. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question