Sign in to follow this  
Flawe

fps counter

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this