Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Effective Time-Keeper

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    19

    Effective Time-Keeper

    Hi,
    I am writing a driving simulation program using GLUT. where in I need 2 write an effective time keeper. would u guess suggest me a good time-keeper using glutTimerFunc for 30 fps.


    regards

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: Effective Time-Keeper

    Originally posted by ajmrm:
    Hi,
    I am writing a driving simulation program using GLUT. where in I need 2 write an effective time keeper. would u guess suggest me a good time-keeper using glutTimerFunc for 30 fps.


    regards
    GLUT timers can be somewhat off in terms of accuracy, especially when your render loop takes longer than the timeout you request.

    For a 30 fps timer, try glutTimerFunc timeout value of ~ 30ms. Also, remember that glut timers are not recuring, so in your timer callback, you have to reset the timer every time.

    For more advanced, and accurate timing you might take a look at some of the GLUT replacement toolkits available. For Win32, I'd highly recommend Cpw.

    Here's a toolkits FAQ: http://www.mathies.com/glfaq/

    Regards,
    Jim




    [This message has been edited by jmathies (edited 11-29-2002).]
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2002
    Posts
    19

    Re: Effective Time-Keeper

    Hi,
    Actually I am calling a func. FeedWater() to feed water in every frame and i restrict to 30fps. I have a loop in the render function from frame 1 to 30 and calling this FeedWater() func @ 33ms.

    Now the problem is once the control goes to the FeedWater() func, I have to create a timer to be there inside that function for 33ms. Here I need to do some operation.

    Listing....
    RenderScene()
    {
    for(frame=1;frame<=30;frame++)
    {
    .......
    time = frame * (1/30);
    FeedWater(time);
    .....
    OutputWater(time);
    }
    .....
    }

    FeedWater(time)
    {
    start_time = GetTickCount();
    time_len = time * 1000;
    final_time = time_length - final_time;
    while((GetTickCount() - start_time) < final_time)
    {
    TimerFunc(final_time);
    .....
    .....
    }
    }

    TimerFunc(int value)
    {
    r1 = rand()%50;
    c1 = rand()%75;
    glutPostRedisplay();
    glutTimerFunc(value, TimerFunc, 1);
    }

    The above listing code is not working fine... pls suggest and help me dude.

    thanx
    regards

  4. #4
    Advanced Member Frequent Contributor marcus256's Avatar
    Join Date
    Aug 2001
    Location
    Sweden
    Posts
    853

    Re: Effective Time-Keeper

    Hello!

    I see you are using GetTickCount(), which is a Windows specific function (not GLUT and not portable). It also happens to be one of the worst timer sources in Windows (in terms of resolution). The accuracy of GetTickCount() is usually worse than 10 ms, sometimes as bad as 50 ms as I have heard. Since 30 fps means 33 ms per frame, your timer source is not accurate enough (you will often get the same time for two different frames => problems).

    One of the best, portable, timers around (in my opinion) is the one in GLFW , which normally has a resolution better than 1 us. It automatically choses the best timer source for the target platform (e.g. RDTSC CPU instruction for Pentium-class x86 systems, free running hardware counter @ > 1 MHz for SGI stations, etc).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •