View Full Version : how to use timer with x window

03-19-2002, 06:43 AM
I am using glx to develop opengl program, how can I add a timer to my opengl window so that I can implement an animation?

03-19-2002, 02:47 PM
this is a cross post. see the same post in the other forum.

03-20-2002, 12:34 AM
If you need a high resolution timer instead of gettimeofday do you find one here for Intel chips

If you are using Xt do you probably want to use XtAppAddTimeOut that works in a similar way as GLUT timeouts. Some more information is here http://toolbox.sgi.com/linux/documents/OpenGL/overviews.html#OglXIn

03-20-2002, 02:53 PM
Standard C Library Functions gettimeofday(3C)

gettimeofday, settimeofday - get or set the date and time

#include <sys/time.h>

int gettimeofday(struct timeval *tp, void *);

int settimeofday(struct timeval *tp, void *);

The gettimeofday() function gets and the settimeofday()
function sets the system's notion of the current time. The
current time is expressed in elapsed seconds and
microseconds since 00:00 Universal Coordinated Time, January
1, 1970. The resolution of the system clock is hardware
dependent; the time may be updated continuously or in clock

microseconds == 10^-6

[This message has been edited by john (edited 03-20-2002).]

03-20-2002, 11:15 PM
Of course, using GLFW (http://hem.passagen.se/opengl/glfw) makes this much easier. The glfwGetTime() function returns the time in seconds as a doubple precision floating point value. It supports both X11 and Windows. Under Unix, the timer is implemented with gettimeofday or RDTSC (CPU cycle counter on x86 CPUs), and under Windows the timer is implemented with a "performance counter", GetTickCount or RDTSC.

On the GLFW pages you can also find some tutorials, where you can find examples of how to use the timer for animation.

[This message has been edited by marcus256 (edited 03-21-2002).]

03-21-2002, 03:30 AM
Yes, gettimeofday is giving the time in microseconds and that is not enough in all cases. For animations is it of course more than enough but not for everything else. The programmer that did the highres timer also explained why. Perhaps should someone post the man page to him and explain that microseconds== 10^-6. http://www.opengl.org/discussion_boards/ubb/smile.gif