Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6374201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:27:31+00:00 2026-05-25T01:27:31+00:00

I use Glut to make a simple animation. In the main function, glutTimerFunc(TIMERMSECS, animate,

  • 0

I use Glut to make a simple animation. In the main function, glutTimerFunc(TIMERMSECS, animate, 0) is called. The two pieces of codes generate the same graphic.

const int TIMERMSECS = 20;
float animation_time = 0;
const float  animation_step = .5;

Method 1:

   void animate(int t){
        float time_elapsed = TIMERMSECS/1000.0;
        float current_step = animation_step* time_elapsed;
        glutTimerFunc(TIMERMSECS, animate, 0);
        if(current_step < animation_step*2) 
                animation_time += current_step;
        glutPostRedisplay();
}

Method 2:

   void animate(int t){
        float time_elapsed = TIMERMSECS/1000.0;
        float current_step = animation_step* time_elapsed;      
        if(current_step < animation_step*2) 
                animation_time += current_step;
        glutPostRedisplay();
       glutTimerFunc(TIMERMSECS, animate, 0);
}

The only difference between them is the position of glutTimerFunc. For Method 1, it looks like a recursive that will never reach the end of animate()function. But why does that still work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:27:32+00:00Added an answer on May 25, 2026 at 1:27 am

    glutTimerFunc will not immediately call the timer function under any circumstances. Even if the time is 0. It always waits for the message processing loop, and even then it will only call the requested function when all other message processing has completed. That way, important messages like “repaint window” and “resize window” still get processed.

    In general, you should not rely on the timer function being particularly accurate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

every introduction and sample that I can find seems to use GLUT or some
I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom
use LWP::Simple; use Parallel::ForkManager; @links=( [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-windows.exe,SweetHome3D-2.1-windows.exe], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3D-2.1-macosx.dmg,SweetHome3D-2.1-macosx.dmg], [http://prdownloads.sourceforge.net/sweethome3d/SweetHome3DViewer-2.1.zip,SweetHome3DViewer-2.1.zip], ); # Max 30 processes for
I'm creating an OpenGL application on windows. I can't use GLUT, because I would
GLUT is a great API and it's very easy to use but I am
I have a standard glut implementation. The display function redraws each object, but I
I'm trying to use GLUT (freeglut) in my OpenGL application, and I need to
I'm trying to make a small game using (free)GLUT. I know that it's old
I'm attempting to make a chromed cube in GLUT / OpenGL and I'm not
My code so far for the main function of the OpenGL program is basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.