From 72e6d5bb058d8c8e6cf93e82188bf20e6385ba8c Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Wed, 20 Nov 2019 20:53:50 +0300 Subject: [PATCH] Replace gluOrtho2D with own implementation --- src/celengine/console.cpp | 8 ++++---- src/celengine/overlay.cpp | 6 +++--- src/celengine/render.cpp | 12 ++++-------- src/celmath/geomutil.h | 23 ++++++++++++++++++++++- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/celengine/console.cpp b/src/celengine/console.cpp index 8c7eca20..008654fc 100644 --- a/src/celengine/console.cpp +++ b/src/celengine/console.cpp @@ -11,13 +11,14 @@ #include #include #include -#include "celutil/utf8.h" +#include +#include #include #include "vecgl.h" #include "console.h" using namespace std; - +using namespace celmath; static int pmod(int n, int m) { @@ -74,8 +75,7 @@ void Console::begin() { glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, xscale, 0, yscale); + glLoadMatrix(Ortho2D(0.0f, (float)xscale, 0.0f, (float)yscale)); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); diff --git a/src/celengine/overlay.cpp b/src/celengine/overlay.cpp index 296d3fac..1da2d12d 100644 --- a/src/celengine/overlay.cpp +++ b/src/celengine/overlay.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "vecgl.h" #include "overlay.h" #include "rectangle.h" @@ -21,7 +22,7 @@ using namespace std; using namespace Eigen; - +using namespace celmath; Overlay::Overlay(const Renderer& r) : ostream(&sbuf), @@ -34,8 +35,7 @@ void Overlay::begin() { glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, windowWidth, 0, windowHeight); + glLoadMatrix(Ortho2D(0.0f, (float)windowWidth, 0.0f, (float)windowHeight)); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 49eb2caa..d815d0e6 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -2423,8 +2423,7 @@ void Renderer::render(const Observer& observer, glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 ); + glLoadMatrix(Ortho2D(0.0f, 1.0f, 0.0f, 1.0f)); glMatrixMode (GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); @@ -7095,8 +7094,7 @@ void Renderer::renderAnnotations(const vector& annotations, FontStyl glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, windowWidth, 0, windowHeight); + glLoadMatrix(Ortho2D(0.0f, (float)windowWidth, 0.0f, (float)windowHeight)); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); @@ -7229,8 +7227,7 @@ Renderer::renderSortedAnnotations(vector::iterator iter, glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, windowWidth, 0, windowHeight); + glLoadMatrix(Ortho2D(0.0f, (float)windowWidth, 0.0f, (float)windowHeight)); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); @@ -7316,8 +7313,7 @@ Renderer::renderAnnotations(vector::iterator startIter, glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, windowWidth, 0, windowHeight); + glLoadMatrix(Ortho2D(0.0f, (float)windowWidth, 0.0f, (float)windowHeight)); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); diff --git a/src/celmath/geomutil.h b/src/celmath/geomutil.h index 9ed8e720..12c4e5d0 100644 --- a/src/celmath/geomutil.h +++ b/src/celmath/geomutil.h @@ -115,6 +115,27 @@ Perspective(T fovy, T aspect, T nearZ, T farZ) return m; } -}; // namespace celmath +/*! Return an orthographic projection matrix + */ +template Eigen::Matrix +Ortho(T left, T right, T bottom, T top, T nearZ, T farZ) +{ + T rl = right - left; + T tb = top - bottom; + T fn = farZ - nearZ; + Eigen::Matrix m; + m << 2/rl, 0, 0, - (right + left) / rl, + 0, 2/tb, 0, - (top + bottom) / tb, + 0, 0, -2/fn, - (farZ + nearZ) / fn, + 0, 0, 0, 1; + return m; +} +template Eigen::Matrix +Ortho2D(T left, T right, T bottom, T top) +{ + return Ortho(left, right, bottom, top, T(-1), T(1)); +} + +}; // namespace celmath #endif // _CELMATH_GEOMUTIL_H_