Skip to content

Instantly share code, notes, and snippets.

@posva
Created July 22, 2013 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save posva/6052868 to your computer and use it in GitHub Desktop.
Save posva/6052868 to your computer and use it in GitHub Desktop.
Simple FPS display for SFML2
#pragma once
#include <SFML/Graphics/Text.hpp>
#include <SFML/System/Clock.hpp>
#include <sstream>
class FPS : public sf::Text {
sf::Clock myClock;
unsigned int mySteps;
public:
FPS(const sf::Font& font) : sf::Text("0", font), mySteps(0)
{}
void step()
{
++mySteps;
float time(myClock.getElapsedTime().asSeconds());
if (time >= 1.f)
{
std::ostringstream str; str.precision(4);
str<<mySteps/time;
setString(str.str());
mySteps = 0;
myClock.restart();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment