glutTimerFunc issues with Vista

Hey guys,

I’m trying to write some code to perform some animations. It’s required that I use GLUT, so I’m using glutTimerFunc to set the animation timers. A problem arises when running on my Vista desktop. My code is similar to this:


void myTimerCallback(int id)
{
   /* Update animation */
          .
          .
          .
   /* Register callback again to continue the animation */
   glutTimerFunc( timeInterval, myTimerCallback, id);
}

If timeInterval is less than 1000 milliseconds then the callback never gets called and the animation cycle stops unexpectedly. My code compiles and runs fine on another machine with linux.

Has anyone else had this problem, or does anyone have a fix for this?

I solved my problem by modifying the GLUT source. The error that was occuring came from casting a LONGLONG to float. The line is in the definition of function gettimeofday in “win32_util.c”:

Old Code:


      LARGE_INTEGER f;
      QueryPerformanceFrequency(&f);
      tp->tv_sec = t.QuadPart/f.QuadPart;
      tp->tv_usec = ((float)t.QuadPart/f.QuadPart*1000*1000) - (tp->tv_sec*1000*1000);

New Code:


      LARGE_INTEGER f;
      double t_over_f;
      QueryPerformanceFrequency(&f);
      tp->tv_sec = t.QuadPart/f.QuadPart;
      t_over_f = ((double)t.QuadPart/f.QuadPart);
      tp->tv_usec = (t_over_f - tp->tv_sec)*1000*1000;

The float precision was affecting the result, so I used a double in its place. So far, so good. I hope someone finds this useful someday. If you need help with this send me an email: ogz at ku edu.

I’m a bit of a beginner when it comes to this stuff. I’ve tried to adjust and compile the code but I can’t figure out how to compile it. If you know how, it’s not even five minutes worth of work. Could anyone do me a favor and send me the compiled binaries? My email is mvanloocke@gmail.com

Assuming you use MS Visual Studio :
http://blog.thegabrielflores.com/2008/02/installing-freeglut-on-visual-studio.html