• 13
• 16
• 27
• 9
• 9

# fps counter

This topic is 4678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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:

    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.

##### Share on other sites
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 =)

##### Share on other sites
To the dark side of the power I have switched, Master Yoda, C/C++ I presently use [lol]

##### Share on other sites
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.

##### Share on other sites
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)