#define SFML_STATIC
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#pragma comment(lib, "sfml-graphics-s-d.lib")
#pragma comment(lib, "sfml-window-s-d.lib")
#pragma comment(lib, "sfml-system-s-d.lib")
#include <string>
#include <vector>
using namespace std;
void drawFps(sf::RenderWindow &wnd, sf::Clock &clock, sf::Font &font){
float currentTime = clock.restart().asSeconds();
float fps = 1.f / currentTime;
sf::Text tx;
tx.setString(to_string((int)fps).c_str());
tx.setPosition(600.0f,500.0f);
tx.setFont(font);
tx.setCharacterSize(16);
wnd.draw(tx);
}
class Messages{
public:
static sf::Vector2i position;
static vector<string> messages;
static void AddDummyMessage(){
messages.push_back("This is a test message, because test.");
}
};
sf::Vector2i position = sf::Vector2i(0,0);
vector<string> Messages::messages;
void DisplayMessages(sf::RenderWindow &wnd, sf::Font &font){
sf::Text tx;
tx.setFont(font);
tx.setCharacterSize(16);
int offset = 0;
for(auto e : Messages::messages){
tx.setPosition(position.x * 16, position.y * 16 + offset++*16);
tx.setString(e);
wnd.draw(tx);
}
}
int main()
{
sf::RenderWindow wnd(sf::VideoMode(800,600,32), "Test");
sf::Event evt;
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Clock clock;
while(wnd.isOpen()){
wnd.clear();
while(wnd.pollEvent(evt)){
if(evt.type == sf::Event::KeyPressed && evt.key.code == sf::Keyboard::Space){
Messages::AddDummyMessage();
}
}
DisplayMessages(wnd, font);
drawFps(wnd, clock, font);
wnd.display();
}
}