Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

In XNA, the system calls update and draw function with the time information. This contains information such as how much time has passed since last update was called. This makes easy to integrate time and do animation calculation accordingly. But I dont see any such mechanism in openGL. I see openGL requires programmers to have their own implementation which could be buggy or inefficient. Is there any standard (and efficient) code that demonstrate this practice in openGL?

share|improve this question
up vote 3 down vote accepted

XNA can do this because it knows it's sitting on top of a Windows-like platform, and therefore has Windows-compatible timer functions. OpenGL can sit on top of any OS, and therefore it can't provide any such thing itself.

GLFW provides a lightweight cross-platform wrapper around OpenGL, including high-precision timing routines.

This is also something that is fairly straightforward to implement yourself, using QueryPerformanceCounter on Windows, mach_absolute_time on OS X, and clock_gettime on POSIX (e.g. Linux).

share|improve this answer
There is no timer in OpenGL but it is strange. Running on multiple OSes isn't a reason. OpenGL is a framework for abstracting away from needing to know the OS and GPU. For example the XNA Framework works on WP7, Windows and the Xbox 360, 3 completely different machines (little endian, big endian, arm, x86) however since the XNA framework was written for all these systems, all these systems have the same time interface. (This could be easily added to OpenGL). However XNA is a game making framework (which always needs timing), while OpenGL is a graphics framework, so maybe that's the reason? – Roy T. Jun 27 '11 at 6:18
OpenGL has never been a framework for abstracting away from the OS. OpenGL ES contains the first tiny steps towards such a thing with EGL. It exists to abstract away graphics card hardware. (Also, all three devices you name contain a Windows-based kernel, DirectX, and a CLR implementation. XNA depends on at least the latter two and probably in its primary incarnation a bit of the former as well.) – user744 Jun 27 '11 at 8:54
@Roy T. Yes, OpenGL is "Open Graphics Library", timing your game is logic and hence is not in the lib. This is also why OpenAL is a serperate library. XNA provides a framework for game development and hence tries to encompass everything needed. – Jonathan Connell Jun 27 '11 at 13:58
Thanks for the suggestion. I think POSIX is a better option. Its also supported on mobile platforms like iPhone, Android etc. – Vijayendra Tripathi Jun 28 '11 at 19:54
You will need all three of those, assuming you want to port. – user744 Jun 28 '11 at 20:15

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.