Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make a countdown timer for my racing game such as "3... 2... 1... GO!" I'm using GLUT, OpenGL, and C++. I was wondering what the most appropriate method to handle this in C++. clock()? glutTimerFunc()? I plan on having 4 textured polygons that shrink and fade one after the other.

share|improve this question
You could code your own time manager using glutGet(GLUT_ELAPSED_TIME); That way you have real frame time correlation with what the user should see on their screen. Some code here. That's probably easier since you don't have to worry about performing really OS specific time calls. – teodron Apr 10 '12 at 17:35
up vote 2 down vote accepted

You need to accumulate time in your update loop. Don't think in terms of "what time it is", instead, keep a double variable, called timeTotal. Each frame, increment it by (1.0/60.0) (or whatever your fixed timestep is). When the game starts, you can reset the timer, and your race start introduction would just go something like this:

void update()
  totalTime += 1.0/60.0 ; //increase time

  if( timeTotal > 1 )  // 3.
  else if( timeTotal > 2 )  // 2.
  else if( timeTotal > 3 )  // 1
  else { GO } // race on


You can refactor this in any number of ways, but this is the basic idea of how to trip time based events in a game system.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.