diff options
| author | hachem <im@hachem.wtf> | 2025-08-09 21:07:53 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-08-09 21:07:53 +0200 |
| commit | ed6de8793f267fb1fc5c9af2e68cd4e573ee1d25 (patch) | |
| tree | e2bcc2311cd3f3d7d13ddf4af39a967f7e975735 /src/Core/Window.cpp | |
| parent | 586cde2360b16cfd4cf1d297b989e722ea80a64f (diff) | |
[add]: Window creation
Diffstat (limited to 'src/Core/Window.cpp')
| -rw-r--r-- | src/Core/Window.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp new file mode 100644 index 0000000..8f1c6ea --- /dev/null +++ b/src/Core/Window.cpp @@ -0,0 +1,46 @@ +#include "Window.h" +#include <cstdint> + +namespace Donut +{ + static bool s_GLFWInitialized = false; + static uint32_t s_GLFWWindowCount = 0; + + Window::Window(const std::string& title, int width, int height) + : m_Title(title), m_Width(width), m_Height(height) + { + if (!s_GLFWInitialized) + { + glfwInit(); + s_GLFWInitialized = true; + } + + m_Window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); + glfwMakeContextCurrent(m_Window); + + s_GLFWWindowCount++; + } + + Window::~Window() + { + glfwDestroyWindow(m_Window); + s_GLFWWindowCount--; + + if (s_GLFWWindowCount == 0) + { + glfwTerminate(); + s_GLFWInitialized = false; + } + } + + void Window::OnUpdate() const + { + glfwPollEvents(); + glfwSwapBuffers(m_Window); + } + + bool Window::ShouldClose() const + { + return glfwWindowShouldClose(m_Window); + } +}
\ No newline at end of file |
