9
9
10
10
#include < array>
11
11
#include < chrono>
12
- #include < iostream>
13
12
#include < memory>
14
13
15
14
namespace {
@@ -44,6 +43,10 @@ int main()
44
43
auto window = sf::RenderWindow (sf::VideoMode ({ image_width, image_height }), " Raytracer" );
45
44
window.setFramerateLimit (30 );
46
45
46
+ auto font = sf::Font ();
47
+ if (!font.loadFromFile (FONT_PATH / std::filesystem::path (" font.ttf" )))
48
+ throw std::runtime_error (" Failed to load font" );
49
+
47
50
// Heap allocate to accomodate systems with small (<1MB) stack sizes
48
51
const auto pixels_allocation = std::make_unique<std::array<std::array<sf::Color, image_width>, image_height>>();
49
52
auto & pixels = *pixels_allocation;
@@ -66,7 +69,6 @@ int main()
66
69
67
70
const auto rendering_time
68
71
= std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now () - start_of_rendering);
69
- std::cout << " Rendered in " << rendering_time.count () << " ms" << std::endl;
70
72
71
73
auto image = sf::Image ();
72
74
image.create ({ image_width, image_height }, reinterpret_cast <uint8_t *>(pixels.data ()));
@@ -75,6 +77,10 @@ int main()
75
77
throw std::runtime_error (" Failed to load texture" );
76
78
const auto sprite = sf::Sprite (texture);
77
79
80
+ auto text = sf::Text (std::to_string (rendering_time.count ()) + " ms" , font, 28 );
81
+ text.setPosition ({ 5 , 0 });
82
+ text.setOutlineThickness (2 .f );
83
+
78
84
while (window.isOpen ()) {
79
85
for (auto event = sf::Event (); window.pollEvent (event);) {
80
86
switch (event.type ) {
@@ -88,6 +94,7 @@ int main()
88
94
89
95
window.clear ();
90
96
window.draw (sprite);
97
+ window.draw (text);
91
98
window.display ();
92
99
}
93
100
}
0 commit comments