Axis and grid are drawn over custom mesh in libQGLViewer >2.6.x after using drawText()
dennis2society opened this issue · 2 comments
Hi,
I am using libQGLViewer in one of my own projects and after upgrading it to >2.6.x I see the axis and grid drawn over my own custom mesh. This does not happen in 2.6.3. The issue could be reproduced with libQGLViewer 2.8.0 and 2.9.1. For me it looks like there is a depth test missing. Funnily enough this does not happen for the spiral that is drawn as default.
I have tried adding additional depth tests to my own drawing code but to no avail.
Any idea what could be causing this?
Screenshot with libQGLViewer 2.6.3 (this is how it should look):
I have subsequently disabled parts of my own code to ensure that none of my own code breaks things to find the actual cause of this and finally had success after disabling all my calls to the QGLViewer::drawText() function.
By adding a simple drawText() call I can even reproduce the issue with the default spiral:
This happens before any of my own drawing code is even called.
Example code (the implemented draw() function in my QGLViewer app):
//// Draws a spiral
const float nbSteps = 200.0;
const uint nb = static_cast<uint>(nbSteps);
glBegin(GL_QUAD_STRIP);
for (auto i = 0; i < nb; ++i) {
float ratio = i / nbSteps;
float angle = 21.0 * ratio;
float c = cos(angle);
float s = sin(angle);
float r1 = 1.0 - 0.8 * ratio;
float r2 = 0.8 - 0.8 * ratio;
float alt = ratio - 0.5;
const float nor = .5;
const float up = sqrt(1.0 - nor * nor);
glColor3f(1.0 - ratio, 0.2f, ratio);
glNormal3f(nor * c, up, nor * s);
glVertex3f(r1 * c, alt, r1 * s);
glVertex3f(r2 * c, alt + 0.05, r2 * s);
}
glEnd();
glColor3f(0.8f, 0.8f, 0.1f);
QFont f;
f.setPointSize(18);
drawText(10, 75, "This text messes up the axis and grid drawing...", f);
Never mind... After digging around in qglviewer.cpp and thoroughly looking at the code for drawText I have found a sequence of glDisable/Enable(GL_LIGHTING/GL_DEPTH_TEST/CULL_FACE) before+after the drawText() calls which mostly fix the issue. Obviously this is not an issue in QGLViewer but in my own code.