From d7c1ced08d5d78fcb239550404db4e67d4357a19 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 22 Sep 2026 06:57:16 +0200 Subject: fix: windows support --- src/core/window.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/core/window.cpp') diff --git a/src/core/window.cpp b/src/core/window.cpp index 9a8d1ec..8bb4d7e 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -24,6 +24,8 @@ namespace Donut { DONUT_INFO("Initializing window: ", m_title, " (", m_width, "x", m_height, ")"); + glfwSetErrorCallback(glfw_error_callback); // before init, so a failing init says why + if (!s_glfw_initialized) { int success = glfwInit(); @@ -44,23 +46,26 @@ namespace Donut } else { -#ifdef __APPLE__ - // macOS caps OpenGL at 4.1 Core Profile and demands a forward-compat - // core-profile context for anything modern (>= 3.3) to even compile. - // skip these hints and GLFW hands you a dusty 2.1 context and every - // single shader in the project refuses to build. so, we ask nicely: + // the shaders are GLSL 4.10 core, so ask for exactly that everywhere. + // macOS caps OpenGL at 4.1 and also wants forward-compat for anything + // past 2.1, or every shader in the project refuses to build. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); #endif } + // size the window in physical pixels for the monitor's scale (windows/x11; + // a no-op on macos, where the framebuffer scales instead) + glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); m_window = glfwCreateWindow(m_width, m_height, m_title.c_str(), nullptr, nullptr); if (!m_window) { DONUT_ERROR("Could not create GLFW window!"); glfwTerminate(); + s_glfw_initialized = false; return; } @@ -70,7 +75,6 @@ namespace Donut glfwMakeContextCurrent(m_window); glfwSetWindowUserPointer(m_window, this); - glfwSetErrorCallback(glfw_error_callback); glfwSetWindowCloseCallback(m_window, glfw_window_close_callback); glfwSetWindowSizeCallback(m_window, glfw_window_size_callback); glfwSetWindowFocusCallback(m_window, glfw_window_focus_callback); @@ -87,6 +91,7 @@ namespace Donut auto Window::shutdown() -> void { DONUT_INFO("Shutting down window: ", m_title); + if (!m_window) return; // creation failed, and init() already cleaned up GLFW glfwDestroyWindow(m_window); s_glfw_window_count--; -- cgit v1.3