manvis
12th February 2014, 18:05
I’m using Qt 5.2, on Windows 7, MinGW 32 bit version. I’m trying to overlay some 2d text over an OpenGL 3.3 context using QPainter.
Here’s the code I’m using to set up the font:
m_font = QFont ("Times", 15, QFont::Light, true);
Here’s the code I’m using for drawing:
if (!m_paintDevice){
m_paintDevice = new QOpenGLPaintDevice;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_paintDevice->setSize(size());
QPainter painter(m_paintDevice);
painter.setRenderHint(QPainter::Antialiasing);
painter.beginNativePainting();
// OpenGL draw calls go here.
painter.endNativePainting();
m_defaultPen.setColor(Qt::white);
painter.setPen(m_defaultPen);
painter.setFont(m_font);
painter.drawText(m_defaultRect, Qt::AlignCenter, "This is a test.");
All other code is pretty much identical to the example found here https://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html.
This is the result I’m getting:
10041
I’ve tried multiple different font families (Arial, Compacta, etc.), yet this problem persisted. The only thing that can slightly mitigate it, is the increase in QFont size (50+ has little to none of these distortions).
Does anyone know how to solve this problem?
Here’s the code I’m using to set up the font:
m_font = QFont ("Times", 15, QFont::Light, true);
Here’s the code I’m using for drawing:
if (!m_paintDevice){
m_paintDevice = new QOpenGLPaintDevice;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_paintDevice->setSize(size());
QPainter painter(m_paintDevice);
painter.setRenderHint(QPainter::Antialiasing);
painter.beginNativePainting();
// OpenGL draw calls go here.
painter.endNativePainting();
m_defaultPen.setColor(Qt::white);
painter.setPen(m_defaultPen);
painter.setFont(m_font);
painter.drawText(m_defaultRect, Qt::AlignCenter, "This is a test.");
All other code is pretty much identical to the example found here https://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html.
This is the result I’m getting:
10041
I’ve tried multiple different font families (Arial, Compacta, etc.), yet this problem persisted. The only thing that can slightly mitigate it, is the increase in QFont size (50+ has little to none of these distortions).
Does anyone know how to solve this problem?