jogl fps lock

how can i lock frame rate let’s say to 50fps in jogl?

do i need to create own animator class or how?

You can measure your frame time at the beginning of your display() method and Thread.sleep() or Object.wait() for the remainder of say 20 ms.

Someone was posting on the gl4java mailing list about this recently and it probably should be added to the Animator class.

However think about why you want to do this – is it to keep CPU usage down? Or to avoid looking at wall clock time in your animation loop? If it’s the latter then you should probably consider adding a notion of elapsed time to your animations, because doing so will provide framerate independence.

keeping CPU usage down is always a good thing if you want to increase stablity on all systems. I’ve notice on one of my systems that I will lockup occassionally playing games or doing cpu intensive stuff that run at full cpu usage for prolong periods of times. Its my guess that I lock up because of the extra heat that my cpu/video card is producing.

IMO I’m thinking a frame lock might not be a bad idea since I’m sure it would have much tighter accuracy then me placing a sleep in my code. I know gage has a more accurate timer and a native timer could be used but we are talking about a Java 3d gaming API and ease of use/robustness of its current framework should be one of its aims.

Just a though,
Mark

If you look at the code for the Animator class, the main thread runs in a tight loop with no sleep() or yield(). This is not very swing friendly, and I noticed that in some of my practice programs, the gui interaction was very jerky.

Please put in FPS functionality, so swing events can be handled in a timely fashion and so we can drive other functions like AI, etc. within controlled timeslices.

I ended up cut and pasting the Animator class to my own package and adding a sleep(33) within the run loop. Oh by the way, is the GLCanvas.willSetRenderingThread() supposed to be protected? or was the “public” modifier left off by accident? Can it be public so we can use the NVidia bug fix from classes we make from scratch?

If you don’t want to mess with the Animator class, I bet you can just put a sleep() line at the end of your display() code. I don’t bother with calculating the exact time delta, right now, because my notebook fps tops at 30fps, and I’m on winXP so the timer is not accurate anyways.

After the sleep fix, my programs run just like it did in GL4Java, except for any demo with teapots…Can anyone port the glutTeapot() soon? I really like the teapot!

currently i run also own animator with sleep,hopefully they integrate GLAnimCanvas like in gl4java, this allow’s FPS locking stuff…

I think that a Fps-lock like we know and love it from Gl4java via myGLcanvas.setAnimateFps(50) is a must-have. (This is no complain, because Jogl is very young, it’s just a suggestion. :slight_smile:

There are many cases where the animation of the GLcanvas suffices with 50 fps (or any other value).

In the model-view-controller (MVC) system of a few full-price games I know it’s usual to limit the FPS of the view-part to a fixed value (changable via option maybe) so that the fixed timer based model-part driving the simulation got it’s CPU time in a reliable way.

Always better to be relatively slow consistently than to speed up and slow down all the time :slight_smile: