Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  jogl fps lock  (Read 2951 times)
0 Members and 1 Guest are viewing this topic.
Offline starlord

Junior Member





« Posted 2003-06-20 04:31:40 »

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

do i need to create own animator class or how?

Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2003-06-23 06:17:10 »

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.
Offline vydias

Senior Newbie




Welcome to my world!


« Reply #2 - Posted 2003-07-05 17:24:28 »

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oneyoon

Junior Newbie




Java games rock!


« Reply #3 - Posted 2003-07-05 23:40:31 »

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!

Offline starlord

Junior Member





« Reply #4 - Posted 2003-07-06 03:41:53 »

currently i run also own animator with sleep,hopefully they integrate GLAnimCanvas like in gl4java, this allow's FPS locking stuff..
8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 151