Replace gluOrtho2D with own implementation

pull/3/head
Hleb Valoshka 2019-11-20 20:53:50 +03:00
parent bf2f4cb236
commit 72e6d5bb05
4 changed files with 33 additions and 16 deletions

View File

@ -11,13 +11,14 @@
#include <cstdarg>
#include <cassert>
#include <algorithm>
#include "celutil/utf8.h"
#include <celutil/utf8.h>
#include <celmath/geomutil.h>
#include <GL/glew.h>
#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();

View File

@ -13,6 +13,7 @@
#include <GL/glew.h>
#include <Eigen/Core>
#include <celutil/debug.h>
#include <celmath/geomutil.h>
#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();

View File

@ -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<Annotation>& 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<Annotation>::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<Annotation>::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();

View File

@ -115,6 +115,27 @@ Perspective(T fovy, T aspect, T nearZ, T farZ)
return m;
}
}; // namespace celmath
/*! Return an orthographic projection matrix
*/
template<class T> Eigen::Matrix<T, 4, 4>
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<T, 4, 4> 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<class T> Eigen::Matrix<T, 4, 4>
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_