From 8d0c070971d53eedce1d5f1c4412e08f7f0e8795 Mon Sep 17 00:00:00 2001 From: onelin Date: Fri, 21 Mar 2025 14:04:52 +0100 Subject: Fix setting wrong window resolution The desired resolution is not necessary the actual resolution, so we need to poll for the scaling, which can also be different from monitor to monitor. But polling that stuff seems like a job for another day. See glfwSetWindowContentScaleCallback --- src/core/src/loop.c | 1 + src/rendering/src/window.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/src/loop.c b/src/core/src/loop.c index dd39db1..49810ef 100644 --- a/src/core/src/loop.c +++ b/src/core/src/loop.c @@ -251,6 +251,7 @@ Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight p->bindings_len = 0; p->cam = &default_camera; + glm_ortho_default(45.f, p->cam->per); // TODO: Add global bindings diff --git a/src/rendering/src/window.c b/src/rendering/src/window.c index b755035..a5e7db6 100644 --- a/src/rendering/src/window.c +++ b/src/rendering/src/window.c @@ -162,11 +162,24 @@ Window* init_window_glfw( ret = (Window*)calloc(1, sizeof(Window)); ret->framework = WINDOW_FRAMEWORK_GLFW; ret->renderer = WINDOW_RENDERER_NONE; - glm_ivec2_copy(windowsize, ret->windowsize); ret->window = window; /* Last parameter is used for the renderer */ ret->context = NULL; + { + ivec2 wsize; + vec2 wscaling; + glfwGetWindowContentScale(window, &wscaling[0], &wscaling[1]); + glfwGetWindowSize(window, &wsize[0], &wsize[1]); + + ret->windowsize[0] = (i32)((f32)wsize[0] * wscaling[0]); + ret->windowsize[1] = (i32)((f32)wsize[1] * wscaling[1]); + + INFO("WINDOW CONTENT SCALING: %.2f x %.2f", wscaling[0], wscaling[1]); + INFO("WINDOW SIZE: %d x %d -> %d x %d", wsize[0], wsize[1], ret->windowsize[0], ret->windowsize[1]); + } + + window_poll_events = &glfwPollEvents; //get_time = &platform_get_time_usec; get_time = &platform_get_time_usec; -- cgit v1.3