aboutsummaryrefslogtreecommitdiff
path: root/src/core/window.cpp
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-22 06:57:16 +0200
committerhachem <im@hachem.wtf>2026-09-22 06:57:16 +0200
commitd7c1ced08d5d78fcb239550404db4e67d4357a19 (patch)
tree9c0e218b096d138075cbf6a48e2562d33a8f94ed /src/core/window.cpp
parent270eda6f558c972ec86ad0580f1d3d18afc83a94 (diff)
fix: windows supportHEADmain
Diffstat (limited to 'src/core/window.cpp')
-rw-r--r--src/core/window.cpp17
1 files changed, 11 insertions, 6 deletions
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--;