Jump to content
  • Advertisement
Sign in to follow this  
Eckos

Yet another FPS question

This topic is 3656 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'm trying to implement a FPS counter using Qt4. And all I find is how to do it using Windows. But I don't use windows so it's no help since it's going to be cross-platform. I tried looking up one for QTimer but it came up with no cigar. And wondering if anyone else knows how to do this in Qt4.

Share this post


Link to post
Share on other sites
Advertisement
Frames per second calculation:

1000 / (number of milliseconds a complete frame takes to execute)


Unfortunately c++ doesn't specify a function that allows you to get time at the millisecond resolution. Qt probably does though.

Share this post


Link to post
Share on other sites
It's such a common tool I made a simple FPS counter class. It updates the average FPS every 1 second, because if you update FPS display every frame it is very hard to read. =)


//----------------------------------------------------------------
// C#/XNA FPSCounter Class
//----------------------------------------------------------------
public class FPSCounter
{
float avgFPS;
float counter;
float timer;

//----------------------------------------------------------------
// FPSCounter() - constructor
//----------------------------------------------------------------
public FPSCounter()
{
avgFPS = 0f;
counter = 0;
timer = 0f;
}

//----------------------------------------------------------------
// Update() - FPS calculation given timeElapsed in milliseconds
//----------------------------------------------------------------
public void Update(float timeElapsed)
{
counter++;
timer+=timeElapsed;

if (timer > 999f)
{
avgFPS = counter;
timer = 0f;
counter = 0;
}
}

//----------------------------------------------------------------
// ToString()
//----------------------------------------------------------------
public override string ToString()
{
return avgFPS.ToString();
}

}


If you figure out how to do milliseconds in QT just pass that in. =)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!