diff options
| author | hachem <im@hachem.wtf> | 2024-10-07 10:50:02 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2024-10-07 10:50:02 +0200 |
| commit | 78c72c3b3e42e3e33afe6cd78ae4bc9db09a59f4 (patch) | |
| tree | 937c3ceb31660299486e5d85805121ced444a1ea /src/core/application.cpp | |
| parent | 16afec529705ebe2704cb0a85699797bf971827d (diff) | |
feat: window manager and OpenGL context
Diffstat (limited to 'src/core/application.cpp')
| -rw-r--r-- | src/core/application.cpp | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/core/application.cpp b/src/core/application.cpp index 08d22e8..7322212 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -2,6 +2,10 @@ #include "core/assert.h" #include "core/log.h" +#include "core/window.h" +#include "core/window_manager.h" + +#include <glad/gl.h> #include <chrono> @@ -13,7 +17,7 @@ namespace Hsdbg constexpr float MAX_DELTA_TIME = 0.25f; - constexpr float PLACEHOLDER_RUN_TIME = 1.0f; + constexpr double MINIMIZED_WAIT_TIMEOUT = 0.1; } Application* Application::s_instance = nullptr; @@ -25,10 +29,23 @@ namespace Hsdbg s_instance = this; Log::info("{}: starting up", m_spec.name); + + m_window_manager = std::make_unique<WindowManager>(); + + WindowSpec window_spec; + window_spec.title = m_spec.name; + window_spec.width = m_spec.width; + window_spec.height = m_spec.height; + window_spec.vsync = m_spec.vsync; + + m_window = &m_window_manager->create_window(window_spec); } Application::~Application() { + m_window = nullptr; + m_window_manager.reset(); + Log::info("{}: shutting down after {} frames", m_spec.name, m_frame_count); s_instance = nullptr; @@ -56,7 +73,24 @@ namespace Hsdbg m_time += m_delta_time; m_frame_count += 1; + m_window_manager->poll_events(); + + if (m_window->should_close()) + { + close(); + break; + } + + if (m_window->is_minimized()) + { + m_window_manager->wait_events(MINIMIZED_WAIT_TIMEOUT); + continue; + } + update(); + render(); + + m_window->swap_buffers(); } } @@ -67,7 +101,16 @@ namespace Hsdbg auto Application::update() -> void { - if (m_time >= PLACEHOLDER_RUN_TIME) - close(); + } + + auto Application::render() -> void + { + glViewport(0, + 0, + static_cast<GLsizei>(m_window->framebuffer_width()), + static_cast<GLsizei>(m_window->framebuffer_height())); + + glClearColor(0.09f, 0.09f, 0.11f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } } |
