Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <string>
- #include <sstream>
- #include "object.h"
- void D_DrawText(sf::RenderWindow &win, sf::String &str, float x, float y, std::string text);
- sf::String D_CreateText(sf::Font font, sf::Color color = sf::Color(255,255,255), float size = 16.f);
- template <typename T>
- std::string toStr(T input)
- {
- std::stringstream stream;
- stream << input;
- return stream.str();
- }
- int main()
- {
- // Create the main rendering window
- sf::RenderWindow App(sf::VideoMode(800, 600, 32), "C++ peli", sf::Style::Close);
- sf::Font myFont;
- if (!myFont.LoadFromFile(getenv("windir") + std::string("\\Fonts\\arial.ttf")))
- return EXIT_FAILURE;
- sf::String fps = D_CreateText(myFont, sf::Color(255, 0, 0));
- Object player(App);
- player.Load("img/player.png");
- // Start game loop
- while (App.IsOpened())
- {
- // Process events
- sf::Event Event;
- while (App.GetEvent(Event))
- {
- // Close window : exit
- if (Event.Type == sf::Event::Closed)
- App.Close();
- }
- // Clear the screen (fill it with black color)
- App.Clear(sf::Color(255, 255, 255));
- //D_DrawText(App, 10, 10, "Hello World!", myFont);
- D_DrawText(App, fps, 10, 40, "FPS: " + toStr(1 / App.GetFrameTime()));
- // Display window contents on screen
- App.Display();
- }
- return EXIT_SUCCESS;
- }
- sf::String D_CreateText(sf::Font font, sf::Color color, float size)
- {
- sf::String str;
- str.SetFont(font);
- str.SetColor(color);
- str.SetSize(size);
- return str;
- }
- void D_DrawText(sf::RenderWindow &win, sf::String &str, float x, float y, std::string text)
- {
- str.SetText(text);
- str.SetPosition(x, y);
- win.Draw(str);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement