Commit f14b3515 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Bug related to font corruption by using QPainter::drawText() in GLViewer fixed.

parent ff131e00
......@@ -1431,23 +1431,23 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
// Save OpenGL states.
GLint buffer;
GLboolean depthTest;
GLboolean blend;
GLint blendSrcRGB, blendSrcAlpha;
GLint blendDstRGB, blendDstAlpha;
GLint alignment;
GLfloat glColor[4];
glGetIntegerv( GL_FRAMEBUFFER_BINDING, &buffer );
glGetBooleanv( GL_DEPTH_TEST, &depthTest );
glGetBooleanv( GL_BLEND, &blend );
glGetIntegerv( GL_BLEND_SRC_RGB , &blendSrcRGB );
glGetIntegerv( GL_BLEND_SRC_ALPHA, &blendSrcAlpha );
glGetIntegerv( GL_BLEND_DST_RGB , &blendDstRGB );
glGetIntegerv( GL_BLEND_DST_ALPHA, &blendDstAlpha );
glGetIntegerv( GL_UNPACK_ALIGNMENT, &alignment );
glGetFloatv( GL_CURRENT_COLOR, glColor );
// Retrieve last OpenGL color to use as a font color.
GLfloat glColor[4];
glGetFloatv( GL_CURRENT_COLOR, glColor );
QColor fontColor = QColor( 255.0f*glColor[0], 255.0f*glColor[1], 255.0f*glColor[2], 255.0f*glColor[3] );
// Paint text.
......@@ -1459,10 +1459,12 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
else if( align & Qt::AlignTop )
y += fm.ascent();
glPixelStorei( GL_UNPACK_ALIGNMENT, 4 ); // Mandatory to avoid font corruption while using painter.drawText(...)!
QPainter painter;
painter.begin( this );
painter.setPen( fontColor );
painter.setFont( font );
painter.setRenderHints( QPainter::Antialiasing | QPainter::TextAntialiasing );
for( auto &l : textLines )
{
if( align & Qt::AlignRight )
......@@ -1477,8 +1479,8 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
// Restore OpenGL states.
glPixelStorei( GL_UNPACK_ALIGNMENT, alignment );
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, buffer );
depthTest? glEnable( GL_DEPTH_TEST ) : glDisable( GL_DEPTH_TEST );
blend? glEnable( GL_BLEND ) : glDisable( GL_BLEND );
glBlendFuncSeparateEXT( blendSrcRGB, blendDstRGB, blendSrcAlpha, blendDstAlpha );
glColor4fv( glColor );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment