Lisp HUG Maillist Archive

Synchronizing Animation in CAPI with monitor's vertical sync refresh rate

Hi,

I am currently evaluating Lispworks Enterprise Edition for a 3D sports game, using CAPI
and OpenGL.

I have looked into the provided OpenGL example app (icosahedron), for opengl and balloons.lisp (in CAPI
applications) for synchronizing animation using timers. Since I am right now in the prototype
stage, timer works fine. However at a later stage, when the game may have large number of objects
to be rendered, the animation may get ghosted.

What I am looking at is a way to synchronize my animation with the monitor's vertical refresh rate.
With the timer, I have to specify a delay. I have looked up the CAPI docs, the examples listed, but
did not find a way to schedule either timer or the opengl pane redisplay callback with the vertical refresh 
rate. In my prototype I do use capi:with-atomic-redisplay but I don't know if it does what I intend to, 
which I doubt, because in that case then the schedule timer should not require a delay.

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.

Any ideas how to do this?

Any help appreciated,
Thanks,
Deepak

--
http://deepaksurti.com
To see a miracle, be the miracle.

Re: Synchronizing Animation in CAPI with monitor's vertical sync refresh rate

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'.

 

Re: Synchronizing Animation in CAPI with monitor's vertical sync refresh rate

Cool. I will look up the FFI for lispworks and use display link. I did not go down that path
as I was looking for a direct CAPI solution. But FFI is fine. On the same lines, a Win
solution should also be possible, I guess.

Thanks.

On Tue, Apr 10, 2012 at 2:44 PM, Walantis Giosis <wg@freelance-giosis.com> wrote:

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'.

 




--
http://deepaksurti.com
To see a miracle, be the miracle.
Updated at: 2020-12-10 08:36 UTC