PDA

View Full Version : QPainter drawFont() draws corrupt glyphs



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?

manvis
13th February 2014, 12:53
Strange. I've compiled my program on Ubuntu, and everything looks fine there. Seems that this is a Windows specific issue.
Unfortunately, Win7/8 are the main platforms that we'll be deploying to. What is qt doing differently on Windows? :confused:

anda_skoa
13th February 2014, 13:55
Since this involves OpenGL, it might depend on which of the two approaches it is using.

One is to use native OpenGL, but I think that needs to be provided by the graphics card vendor.
Another one is using ANGLE, to somehow translate GL into Direct3D.

There might even be a way to just use whatever Microsoft provides for OpenGL, but as far as I know that is not anywhere near what all other platforms provide.

Cheers,
_