hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-09 21:07:53 +0200
committerhachem <im@hachem.wtf>2025-08-09 21:07:53 +0200
commitd6b9f6c8fad3e46caca5dc167ce1cbf5ccfb489e (patch)
tree82beb7d9b23a6040f78098cf235a8668d95a7e3c /src/core
parentc88a9da20bb43287b9c52bdc180fd356fd1d352c (diff)
feat: window creation
Diffstat (limited to 'src/core')
-rw-r--r--src/core/window.cpp46
-rw-r--r--src/core/window.h24
2 files changed, 70 insertions, 0 deletions
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 <cstdint>
+
+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);
+ }
+}
diff --git a/src/core/window.h b/src/core/window.h
new file mode 100644
index 0000000..5f0e36e
--- /dev/null
+++ b/src/core/window.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <GLFW/glfw3.h>
+#include <string>
+
+namespace Donut
+{
+ class Window
+ {
+ public:
+ Window(const std::string& title, int width, int height);
+ ~Window();
+
+ bool should_close() const;
+ void on_update() const;
+ private:
+ GLFWwindow* m_window;
+
+ std::string m_title;
+ int m_width;
+ int m_height;
+ bool m_is_closed;
+ };
+}