View Full Version : timer
hi there, i have created a circle using glBegin(GL_LINES);
i have the circle up there. i want to animate it so i changes colors, eg, red then to blue then to yellow etc. im aware that you need a timer function for this. im so lost, can anyone offer a helping hand?
01-08-2006, 03:55 PM
You may measure the elapsed time and update the colour based on the elapsed time, for example switching colour every 1 sec.
ANSI C defines clock() fuction to return the elapsed clocks since CPU is started.
To measure the elapsed time in second;
clock_t clockStart = clock();
// get elapsed time
float elapsedTime = (float)(clock() - clockStart) / CLOCKS_PER_SEC;However, clock() is not so accurate, probably about 10 ms resolution.
To get higher resolution (at least 1 micro second accuracy), you can use gettimeofday() in Unix and Linux, Or QueryPerformanceCounter() in Windows.
Also, GLUT provides timer callback mechanism, too: glutTimerFunc().
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.