From d6b9f6c8fad3e46caca5dc167ce1cbf5ccfb489e Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 9 Aug 2025 21:07:53 +0200 Subject: feat: window creation --- src/core/window.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/window.cpp (limited to 'src/core/window.cpp') diff --git a/src/core/window.cpp b/src/core/window.cpp new file mode 100644 index 0000000..3a6ba2c --- /dev/null +++ b/src/core/window.cpp @@ -0,0 +1,46 @@ +#include "window.h" +#include + +namespace Donut +{ + static bool s_glfw_initialized = false; + static uint32_t s_glfw_window_count = 0; + + Window::Window(const std::string& title, int width, int height) + : m_title(title), m_width(width), m_height(height) + { + if (!s_glfw_initialized) + { + glfwInit(); + s_glfw_initialized = true; + } + + m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); + glfwMakeContextCurrent(m_window); + + s_glfw_window_count++; + } + + Window::~Window() + { + glfwDestroyWindow(m_window); + s_glfw_window_count--; + + if (s_glfw_window_count == 0) + { + glfwTerminate(); + s_glfw_initialized = false; + } + } + + void Window::on_update() const + { + glfwPollEvents(); + glfwSwapBuffers(m_window); + } + + bool Window::should_close() const + { + return glfwWindowShouldClose(m_window); + } +} -- cgit v1.3