Synchronizing Animation in CAPI with monitor's vertical sync refresh rate
http://deepaksurti.com
To see a miracle, be the miracle.
On April 10, 2012 at 10:42 AM Deepak Surti <dmsurti@gmail.com> wrote:
> For example, in Mac OS X using Objective C, I can use something like
> CVDisplayLinkRef.
> http://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/OpenGL-MacProgGuide/opengl_designstrategies/opengl_designstrategies.html.
> [Synchronize with screen
> refresh rate section].
> However, since I am writing the game to be ported on both Mac , Win; a
> platform specific solution is not useful.
I strongly recommend the display link for the Mac version because it's coupled with
the screens refresh rate. It's very easy to interface with this from Lispworks, due
to the fact that it is a C function interface. I did various prototypes and it works
great with OpengL/CAPI. This way I can manipulate OpenGL states from my REPL and see
the result live on the animation window. The display link callback triggers the
drawing code.
On the Mac I tried the following steps and they worked fine:
1) Let the animation render at the display links speed.
2) Decouple the game logic code from the the display link and do it either:
2.1) time(r) driven - either within the same thread with counting time samples or with a separated thread. Both ways work great with Lispworks.
2.2) single-threaded and frame-counting driven (do logic updates for N frames, where N is dependent on the total time used for the previous logic update computation).
Unfortunately I don't know enough about Windows, this requires a web search.
In plain X11/Xlib there is nothing like that, in the past I used 'gettimeofday' to
time everything. Here, I would take a look in the various X extensions - maybe these
provide something like a 'display link callback'.
On April 10, 2012 at 10:42 AM Deepak Surti <dmsurti@gmail.com> wrote:
> For example, in Mac OS X using Objective C, I can use something like
> CVDisplayLinkRef.
> http://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/OpenGL-MacProgGuide/opengl_designstrategies/opengl_designstrategies.html.
> [Synchronize with screen
> refresh rate section].
> However, since I am writing the game to be ported on both Mac , Win; a
> platform specific solution is not useful.
I strongly recommend the display link for the Mac version because it's coupled with
the screens refresh rate. It's very easy to interface with this from Lispworks, due
to the fact that it is a C function interface. I did various prototypes and it works
great with OpengL/CAPI. This way I can manipulate OpenGL states from my REPL and see
the result live on the animation window. The display link callback triggers the
drawing code.On the Mac I tried the following steps and they worked fine:
1) Let the animation render at the display links speed.
2) Decouple the game logic code from the the display link and do it either:
2.1) time(r) driven - either within the same thread with counting time samples or with a separated thread. Both ways work great with Lispworks.
2.2) single-threaded and frame-counting driven (do logic updates for N frames, where N is dependent on the total time used for the previous logic update computation).
Unfortunately I don't know enough about Windows, this requires a web search.
In plain X11/Xlib there is nothing like that, in the past I used 'gettimeofday' to
time everything. Here, I would take a look in the various X extensions - maybe these
provide something like a 'display link callback'.