From 88b109bae6e453796b2fc8546dee4d12fd767d3e Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Mon, 19 May 2025 16:06:12 +0200 Subject: Add logic to maintain the aspect ratio --- src/main/engine/engine.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/main/engine/engine.c') 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 */ -- cgit v1.2.3