From 3d2160056e409ad2508a8bff4288944d37e32f85 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 12 Mar 2014 13:38:24 +0100 Subject: Resurrect QGLWidget::renderText() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The variant taking x, y, z has been broken in all Qt 5.x releases. This is now corrected by making the GL2 paint engine capable of applying a Z translation. Task-number: QTBUG-31156 Change-Id: I119566e9e9577f6cdf7e8bae56cac1e34995e622 Reviewed-by: Jørgen Lind --- src/opengl/qgl.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/opengl/qgl.cpp') diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 1fbff0f0fe..d676abee47 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -4451,12 +4451,6 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font) glDisable(GL_DEPTH_TEST); glViewport(0, 0, width, height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0, width, height, 0, 0, 1); - glMatrixMode(GL_MODELVIEW); - - glLoadIdentity(); } else { setAutoBufferSwap(false); // disable glClear() as a result of QPainter::begin() @@ -4567,19 +4561,21 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con } else if (use_scissor_testing) { glEnable(GL_SCISSOR_TEST); } - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); glViewport(0, 0, width, height); - glOrtho(0, width, height, 0, 0, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); glAlphaFunc(GL_GREATER, 0.0); glEnable(GL_ALPHA_TEST); if (use_depth_testing) glEnable(GL_DEPTH_TEST); - glTranslated(0, 0, -win_z); + + // The only option in Qt 5 is the shader-based OpenGL 2 paint engine. + // Setting fixed pipeline transformations is futile. Instead, pass the + // extra values directly and let the engine figure the matrices out. + static_cast(p->paintEngine())->setTranslateZ(-win_z); + qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font); + static_cast(p->paintEngine())->setTranslateZ(0); + if (!reuse_painter) { p->end(); delete p; -- cgit v1.2.3