glutTimerFunc not up to speed

I am trying to do a simple 2D animation using glutTimerFunc that calls an update of my coordinates and does glutpostredislay. For now I have timer delay at 20 which means that I should get 50 fps.
My animation involves moving an object from point A to point B within t seconds.

However, when I run it, the callback was serviced after more than 20 miliseconds each time. So my animation after t seconds was drawn with only 13 frames (so animation was very jerky).
Is this because my update function has to be more efficient? (right now its just a simple linear extrapolation btw A to B based on time that has passed, so it cant be that…)

I understand that glutTimerFunc provides a lower bound for when the callback is called. So theres no gurantee of the 50fps?
So is there any way to improve this?
Thanks

Just to mention also that my animation lasts very short 1 second and it moves a distance about 300 pixels.
And I was running the animation through ssh to another server where the code resides. Is this a factor too? (ie would it would run smoothly if I ran it on that machine?)

Running through an SSH tunnel will certanly slow down your application.

If you want to archieve a constant speed of your objects, you better not rely on a timer function. It is better to update as fast as possible (e.g. in the glutIdleFunc), measure the time between frames yourself and update the positions depending on the time.

If you absolutely want a constant framerate (for example for reproducable results in multiplayer games), you can do the following (pseudocode):

void idle_func() {
    static float time = 0;
    time += getTimeSinceLastFrame();
    while(time > STEPSIZE) {
        update_scene(STEPSIZE);
        time -= STEPSIZE;
    }
    glutPostRedisplay();
}

I tried your advice by moving stuf to my idle function to display it as fast as possible. This is what I have:

void displayFunc()
{
glClear(GL_COLOR_BUFFER_BIT );
glEnable(GL_TEXTURE_2D);
drawGround();
glDisable(GL_TEXTURE_2D);
worldGroup->drawGroup();
glFlush();
glutSwapBuffers();

}

void idleFunc()
{
/* I have this if statement so that user can chance animation type /
if (running==0){
running = 1;
drawChoice(12);
}
else {
/
update new position based on delta time since last update (done in the updateGroup function) */
worldGroup->updateGroup();
}
glutPostRedisplay();
}

However, it still seems to have jerky animation with about 13 frames in that 1 second.

ie note that i did not measure the time in between frames… (does it mean that it will just refresh as fast as possible?)
And my update function just count the total time that has passed since i started my animation instead of time since last frame.

It doesn’t really matter if you measure time between frames or time from the start, the point is that you should measure it, instead of relying on a timer function…

If the code you posted still runs only at 13 FPS, then this is a performance problem, not a timing problem. How are you drawing things? Try using display lists, vertex arrays or VBOs. You may have to experiment a bit with some rendering methods to find out what’s most efficient in your specific case…

And try testing without SSH tunnel, if that’s possible. And of course, you could just try to disable some of the geometry for testing, just to see if it improves performance.

As you are running over an SSH-tunnel, I assume you are using the X Window System? I did some experiments with some fairly simple geometry over a network connection (client running on a SunOS machine, and GL server running on an NT 4 machine), and there was a very noticable difference in speed if I put the geometry in a display list (i.e. store all geometry on the server).