#include <iostream>
#include <iomanip>
#include <windows.h>
#include <SFML/Graphics.hpp>
class ErrorPrinter {
public:
ErrorPrinter(std::string cause): cause(cause) { }
void print() {
ShowWindow(GetConsoleWindow(), SW_SHOW);
std::cerr << "Program will stop. Error: \n \'" << cause << '\'' << std::endl;
system("PAUSE");
exit(1);
}
private:
std::string cause;
};
class Test {
public:
Test(sf::VideoMode screen = { 250, 150 }, std::string title = "Test"): window(screen, title) { }
void run() {
ShowWindow(GetConsoleWindow(), SW_HIDE);
while(window.isOpen()) {
HandleEvents();
draw();
}
}
private:
void HandleEvents() {
sf::Event e;
while(window.pollEvent(e)) {
switch(e.type) {
case sf::Event::EventType::Closed:
window.close();
break;
default:
break;
}
}
}
void draw() {
window.clear(sf::Color(50, 50, 50));
sf::RenderTexture buffer;
buffer.create(200, 100);
// Top
buffer.draw(std::unique_ptr<sf::Vertex>(new sf::Vertex[2] {
{{0, 0}}, {{200, 0}}
}).get(), 2, sf::Lines);
// Bottom
buffer.draw(std::unique_ptr<sf::Vertex>(new sf::Vertex[2] {
{{0, 99}}, {{200, 99}}
}).get(), 2, sf::Lines);
// Left
buffer.draw(std::unique_ptr<sf::Vertex>(new sf::Vertex[2] {
{{0, 0}}, {{0, 100}}
}).get(), 2, sf::Lines, sf::Transform().translate(0, 0));
// Right
buffer.draw(std::unique_ptr<sf::Vertex>(new sf::Vertex[2] {
{{199, 0}}, {{199, 99}}
}).get(), 2, sf::Lines, sf::Transform().translate(0, 0));
buffer.display();
sf::Texture texture = buffer.getTexture();
sf::Sprite sprite(texture);
window.draw(sprite, sf::Transform().translate(10, 10));
window.display();
}
private:
sf::RenderWindow window;
};
int main() {
try { Test().run(); } catch(std::exception const& e) {
ErrorPrinter(e.what()).print();
}
return 0;
}