From 1f12adbfaee3a9e6cb9b8aa30aceb163fe4a4776 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 9 Oct 2016 17:48:50 +0300 Subject: [PATCH] default ortho projection --- include/cglm-cam.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/include/cglm-cam.h b/include/cglm-cam.h index 419f987..e69b103 100644 --- a/include/cglm-cam.h +++ b/include/cglm-cam.h @@ -65,7 +65,29 @@ glm_ortho(float left, CGLM_INLINE void glm_ortho_default(mat4 dest) { - glm_ortho(-1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, dest); + GLint rect[4]; + float aspectRatio; + + glGetIntegerv(GL_VIEWPORT, rect); + aspectRatio = (float)rect[2]/rect[3]; + + if (rect[2] >= rect[3]) { + glm_ortho(-1.0f * aspectRatio, + 1.0f * aspectRatio, + -1.0f, + 1.0f, + 100.0f, + -100.0f, + dest); + } else { + glm_ortho(-1.0f, + 1.0f, + -1.0f / aspectRatio, + 1.0f / aspectRatio, + 100.0f, + -100.0f, + dest); + } } CGLM_INLINE