Skip to content

Instantly share code, notes, and snippets.

@kenpower
Created October 30, 2013 14:52
Show Gist options
  • Save kenpower/7233967 to your computer and use it in GitHub Desktop.
Save kenpower/7233967 to your computer and use it in GitHub Desktop.
FPS counter for SFML
class FPS
{
public:
/// @brief Constructor with initialization.
///
FPS() : mFrame(0), mFps(0) {}
/// @brief Update the frame count.
///
/// @brief Get the current FPS count.
/// @return FPS count.
const unsigned int getFPS() const { return mFps; }
private:
unsigned int mFrame;
unsigned int mFps;
sf::Clock mClock;
public:
void update()
{
if(mClock.getElapsedTime().asSeconds() >= 1.f)
{
mFps = mFrame;
mFrame = 0;
mClock.restart();
}
++mFrame;
}
};
FPS fps;
while (window.isOpen())
{
// game loop stuff;
fps.update();
std::ostringstream ss;
ss << fps.getFPS();
window.setTitle(ss.str());
}
@chosensty
Copy link

thanks!

@gustavsDev
Copy link

Thanks! This helped my project!

Copy link

ghost commented Jan 31, 2023

thx random people on the internet

@Squidtito
Copy link

Hippity hoppity your code is now my property

@HappyGoFishing
Copy link

It would be nice if there were a built in FPS count widget (like in RayLib).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment