# Frame timing for GLFW versus GLUT

I need a library which ensures me that the timing between frames are more constant as possible during an experiment of visual psychophics.

This is usually done synchronizing the refresh rate of the screen with the main loop.

For example if my monitor runs at 60Hz I would like to specify that frequency to my framework.

For example if my gameloop is the following

void gameloop() {

// do some computation

printDeltaT(); Flip buffers }

I would like to have printed a constant time interval. Is it possible with GLFW?

Well, the amount of time that passes between frames is highly dependent on the hardware rendering your scene. If the machine just isn't strong enough, there's no way to enforce a fixed frame-rate. However, GLFW DOES allow for very precise time MEASUREMENT (and glut does not), and therefore you can use it to make sure your frame rate is not too FAST. Too slow is another concern entirely.

So on one machine of reasonable speed, yes.

Here's how GLFW does it under the covers, if you want to get straight to the timer and skip GLFW entirely.

And, if you're strictly talking about syncing the buffer swap to the monitor refresh rate, you can use glfwSwapInterval(1); to block buffer swapping until the monitor has done at least one vertical retrace since the last buffer swap. This basically caps your framerate at your monitor's refresh rate.

• Obviosuly I think my computer is able to carry some small computations in less than 1/100 sec. Ok seems that using glfw helps in setting up an accurate timing procedure. I'll let you know after some experiments on different platform, meanwhile a +1 for you super-fast answer – linello Nov 28 '12 at 21:17

Unfortunately, desktop hardware is not designed for "real time" applications, where "real time" is defined as "thing X has to happen exactly at N".

As computers get faster, we're edging closer to that goal, but at the same time the devices try to do more and more things at the same time.

In other words - while your graphics hardware may be capable of rendering whatever you're doing at smooth 60hz, nothing stops the operating system from deciding, all of a sudden, that you have to start downloading patches to the instant messenger you've never even launched, which in turn requires the system to spin up the hard drive that was put to sleep some time ago, which again may cause some interrupt request noise and ends up causing you to miss a frame at some border case..

So what I'm trying to say is, this has little to do with GLUT or GLFW (although you should never use GLUT for anything serious), and the problem is of a bigger scale. Maybe if you build a bare-bones linux distribution that will never, ever do anything behind the scenes..

Or you can just live with the fact that you may experience some rare frame jitters.