From 4a95664342833931836b9b60c588e5bb8413b184 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Wed, 24 Jan 2024 23:09:59 +0000 Subject: [PATCH] main: Clean up, handle resize Handle window resizes by resizing the view frame as well. Clean up the event handling to allow interleaving other code between different checks. Remove early first frame, handle it like the others. --- main.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 73c4dfc..5b9c8d3 100644 --- a/main.cpp +++ b/main.cpp @@ -14,8 +14,7 @@ int main() std::cout << world << std::endl; sf::RenderWindow window(sf::VideoMode(800,600),"Da raycasting"); - world.render(window); - window.display(); + sf::RenderWindow window(sf::VideoMode(1000,1000),"Da raycasting"); sf::Event event{}; sf::Clock frameTime; @@ -23,9 +22,19 @@ int main() { while (window.pollEvent(event)) { - if (event.type == sf::Event::Closed) - window.close(); - else if (event.type == sf::Event::KeyPressed) { + if (event.type == sf::Event::Closed) { + window.close(); + continue; + } + if (event.type == sf::Event::Resized) { + // Keep the view area fit to the window. + sf::FloatRect newView(0, 0, + static_cast(event.size.width), + static_cast(event.size.height)); + window.setView(sf::View(newView)); + continue; + } + if (event.type == sf::Event::KeyPressed) { switch (event.key.code) { case sf::Keyboard::Key::Escape: window.close();