Jump to content
  • Advertisement
Sign in to follow this  
Flawe

fps counter

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!