From 0412ea7b7c32f7f3e06f8336890227f7072fe44e Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 20 Feb 2018 11:30:39 +0100 Subject: [PATCH] glhr::id is now a constant; streamlined applymatrix --- basegraph.cpp | 12 +++++++++++- graph.cpp | 2 +- polygons.cpp | 15 +++++---------- rug.cpp | 2 +- shaders.cpp | 21 ++++++++++++--------- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index c90a8b7c..6e4c70ad 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -218,6 +218,16 @@ void stereo::set_projection(int ed) { stereo::scrdist_text = 0; } else { + + if(hyperbolic && vid.alpha > -1) { + // Because of the transformation from H3 to the Minkowski hyperboloid, + // points with negative Z can be generated in some 3D settings. + // This happens for points below the camera, but above the plane. + // These points should still be viewed, though, so we disable the + // depth clipping + glhr::projection_multiply(glhr::scale(1,1,0)); + } + glhr::projection_multiply(glhr::frustum(vid.xres * 1. / vid.yres, 1)); GLfloat sc = vid.radius / (vid.yres/2.); @@ -893,7 +903,7 @@ void drawCircle(int x, int y, int size, int color) { #if CAP_GL if(vid.usingGL) { glhr::be_nontextured(); - glhr::set_modelview(glhr::id()); + glhr::id_modelview(); glcoords.clear(); glhr::color2(color); x -= vid.xcenter; y -= vid.ycenter; diff --git a/graph.cpp b/graph.cpp index 222697c2..0dd08a45 100644 --- a/graph.cpp +++ b/graph.cpp @@ -2307,7 +2307,7 @@ void drawaura() { } } glhr::switch_mode(glhr::gmVarColored); - glhr::set_modelview(glhr::id()); + glhr::id_modelview(); glhr::prepare(auravertices); glDrawArrays(GL_TRIANGLES, 0, size(auravertices)); diff --git a/polygons.cpp b/polygons.cpp index 85bdd431..4a518670 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -232,16 +232,11 @@ void glapplymatrix(const transmatrix& V) { for(int x=0; x<3; x++) mat[id++] = V[x][y]; mat[id++] = 0; } - {for(int x=0; x<3; x++) mat[id++] = 0;} mat[id++] = 1; - + mat[12] = 0; + mat[13] = 0; mat[14] = GLfloat(vid.alpha); + mat[15] = 1; - if(mat[10] + vid.alpha < 0 && !sphere && !euclid) { - for(int i=0; i<3; i++) - for(int j=0; j<16; j+=4) - mat[j+i] = -mat[j+i]; - } - glhr::set_modelview(glhr::as_glmatrix(mat)); } @@ -259,7 +254,7 @@ void setmatrix(int useV, const transmatrix& V) { glhr::set_modelview(glhr::as_glmatrix(mat)); } else - glhr::set_modelview(glhr::id()); + glhr::id_modelview(); } void gldraw(int useV, const transmatrix& V, const vector& v, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) { @@ -304,7 +299,7 @@ void gldraw(int useV, const transmatrix& V, const vector& v, int ps, i make_array(-xx, +yy, stereo::scrdist) }; glhr::vertices(scr); - glhr::set_modelview(glhr::id()); + glhr::id_modelview(); glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, 0, 4); glhr::vertices(v); setmatrix(useV, V); diff --git a/rug.cpp b/rug.cpp index 525df032..558f7a53 100644 --- a/rug.cpp +++ b/rug.cpp @@ -1179,7 +1179,7 @@ void drawRugScene() { for(int t=0; tuniforms[UNIFORM_NORMAL_MATRIX], 1, 0, nm[0]); } +void id_modelview() { + glUniformMatrix4fv(current->uMVP, 1, 0, projection.as_array()); + } + #endif void color2(int color, ld part = 1) { @@ -436,7 +439,7 @@ void init() { #endif #if CAP_SHADER - projection = id(); + projection = id; for(int i=0; i<4; i++) { flagtype f = flags[i];