From 9a1b0eb36cf9200b190f58af2c8289f5690dd0be Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Tue, 20 May 2025 18:10:28 +0200 Subject: Add logic to keep the ratio on resizing the window --- src/main/engine/engine.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c index 92222bb..ab595ac 100644 --- a/src/main/engine/engine.c +++ b/src/main/engine/engine.c @@ -185,8 +185,15 @@ engine_on_ui_expose(UIEventResize *er) /* Objects in the rendering area must maintain the proportions. So, let's enable Ortho */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); - float aspect = (float)er->width / (float)er->height; - glOrtho(-aspect, aspect, -1, 1, -1, 1); + + float aspect; + if (er->width >= er->height) { + aspect = (float)er->width / (float)er->height; + glOrtho(-aspect, aspect, -1, 1, -1, 1); + } else { + aspect = (float)er->height / (float)er->width; + glOrtho(-1, 1, -aspect, aspect, -1, 1); + } /* Returns to the model view */ glMatrixMode(GL_MODELVIEW); -- cgit v1.2.3