fps counter
I saw some other threads about this but didnät really understand a thing. I use an Animator (java and Jogl) which alls teh display() method and renders all teh graphics continuously. But how can I include this into an fps counter if the Animator object is calling the display() method by itself?
Thanx
Back in a galaxy far far away when I used to be a Java Jedi and accessed OpenGL through the JoGL binding, I did something like that to measure my FPS:
Don't forget to import sun.misc.Perf;
PS: You can substitute that hidden high resolution timer by the standard System.nanoTime() in tiger. Forget about the milliseconds timer, it's rubbish.
private Perf timer = sun.misc.Perf.getPerf(); private long updateFrequency = timer.highResFrequency()>>1, currentTime = 0, frameTime = timer.highResCounter(), lastTime = timer.highResCounter(); public void display(GLDrawable drawable) { currentTime = timer.highResCounter(); fps++; if(currentTime - lastTime >=updateFrequency) { System.out.println("CelShading: FPS " + String.valueOf(fps<<1) ); lastTime = currentTime; fps = 0; } . . . }
Don't forget to import sun.misc.Perf;
PS: You can substitute that hidden high resolution timer by the standard System.nanoTime() in tiger. Forget about the milliseconds timer, it's rubbish.
Ok, if you're not a Java Jedi anymore...what titel do you have now? :)
If you don't mind me asking...what are you using now instead of Jogl? Because I've seen some of your work and it's really impressive....
And thanx for the help =)
If you don't mind me asking...what are you using now instead of Jogl? Because I've seen some of your work and it's really impressive....
And thanx for the help =)
To the dark side of the power I have switched, Master Yoda, C/C++ I presently use [lol]
Ok fair enough...
I don't have much experience with OpenGl så Java is enough for me right now :P
If you have some time, could you maybe explain how the FPS Counter to jsut wrote above works? Why the bit shifts and that stuff? I can't really get the hang of it. Would be really appreciated.
I don't have much experience with OpenGl så Java is enough for me right now :P
If you have some time, could you maybe explain how the FPS Counter to jsut wrote above works? Why the bit shifts and that stuff? I can't really get the hang of it. Would be really appreciated.
That bit shift is a simple division by two of the timer resolution. I did that because I wanted a frame-counter that would update every half second instead of a waiting a full one.
Since this approach gives you the frame rate corresponding to an elapsed amount of time equal to half second, simply multiply the counter by two to get the normalized value: String.valueOf(fps<<1)
Since this approach gives you the frame rate corresponding to an elapsed amount of time equal to half second, simply multiply the counter by two to get the normalized value: String.valueOf(fps<<1)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement