From 3acec91cdf09f7f6bf2a6376844a4c54f14608a1 Mon Sep 17 00:00:00 2001 From: Sara Gerretsen Date: Wed, 3 Sep 2025 19:48:42 +0200 Subject: [PATCH] Adjusted project organization --- src/main.cpp | 51 ++++++++++++++++++++++++++++++------------------- src/project.cpp | 13 +++++++++++++ 2 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 src/project.cpp diff --git a/src/main.cpp b/src/main.cpp index 9b92157..b99f35f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,41 +1,52 @@ #include "imgui.h" #include "imgui-SFML.h" +#include #include -int main() { - sf::RenderWindow window; +static sf::RenderWindow window{}; +static sf::Clock deltaClock{}; + +void initialize_window() { window.create(sf::VideoMode({ 1280, 720 }), "My window"); window.setFramerateLimit(60); window.setVerticalSyncEnabled(true); +} +void initialize_imgui() { if (!ImGui::SFML::Init(window)) - return -1; + exit(-1); +} - sf::Clock deltaClock; - while (window.isOpen()) +void poll_events() { + while (const std::optional event = window.pollEvent()) { + ImGui::SFML::ProcessEvent(window, *event); + // "close requested" event: we close the window + if (event->is()) + window.close(); + } +} + +extern void setup(); +extern void loop(); +extern void draw_gui(); + +int main() { + initialize_window(); + initialize_imgui(); + setup(); + while (window.isOpen()) { // Event Polling - while (const std::optional event = window.pollEvent()) - { - ImGui::SFML::ProcessEvent(window, *event); - - // "close requested" event: we close the window - if (event->is()) - window.close(); - } - + poll_events(); // Update + loop(); ImGui::SFML::Update(window, deltaClock.restart()); - // ImGui::ShowDemoWindow(); - + draw_gui(); // Render window.clear(); - ImGui::SFML::Render(window); - window.display(); } - - return 0; + return 0; } diff --git a/src/project.cpp b/src/project.cpp new file mode 100644 index 0000000..f661c8e --- /dev/null +++ b/src/project.cpp @@ -0,0 +1,13 @@ +#include +#include + +void setup() { +} + +void loop() { +} + +void draw_gui() { + // draw your GUI + ImGui::ShowDemoWindow(); +}