summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-19 16:06:12 +0200
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2025-05-19 16:06:12 +0200
commit88b109bae6e453796b2fc8546dee4d12fd767d3e (patch)
tree9a111b6c2932dca5996c5a1a9ca9094380041dd2
parentaa978f89352847fb329fbadf4bf050c8fe4c7c25 (diff)
downloadtris-88b109bae6e453796b2fc8546dee4d12fd767d3e.tar.gz
tris-88b109bae6e453796b2fc8546dee4d12fd767d3e.zip
Add logic to maintain the aspect ratio
-rw-r--r--src/main/engine/engine.c18
-rw-r--r--src/main/engine/ui/x11/ui.c1
2 files changed, 18 insertions, 1 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c
index b4d70b0..08823a6 100644
--- a/src/main/engine/engine.c
+++ b/src/main/engine/engine.c
@@ -153,9 +153,27 @@ draw_frames()
engine_calculate_fps();
}
+static void
+engine_on_ui_expose(UIEventResize *er)
+{
+ /* Set the viewport to the window size */
+ glViewport(0, 0, er->width, er->height);
+
+ /* 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);
+
+ /* Returns to the model view */
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
void
engine_loop(void)
{
+ ui_set_resize_listener(engine_on_ui_expose);
ui_set_loop_listener(draw_frames);
/* FPS calculation */
diff --git a/src/main/engine/ui/x11/ui.c b/src/main/engine/ui/x11/ui.c
index 312bdec..7a325ce 100644
--- a/src/main/engine/ui/x11/ui.c
+++ b/src/main/engine/ui/x11/ui.c
@@ -146,7 +146,6 @@ ui_on_resize(XEvent event)
er->height = event.xconfigure.height;
on_resize_event(er);
}
- glViewport(0, 0, event.xconfigure.width, event.xconfigure.height);
}
static void