[Interest] QOpenGLWidget noticeable anti-alising halo around text, bitmaps

Pavel Koshevoy pkoshevoy at gmail.com
Fri Jul 17 08:09:01 CEST 2015


On 7/8/15 01:45, Pavel Koshevoy wrote:
> Hi,
>
> I am porting existing Qt4-based code to Qt5 (5.5.0), switching from 
> QGLWidget to QOpenGLWidget.  In my app I render a bunch of text and 
> bitmaps into a transparent QImage.  The QImage is then alpha-blended 
> in OpenGL on top of video frame (rendered with OpenGL with texture 
> buffer originating from ffmpeg libraries).
>
> I've observed an artifact after the switch to QOpenGLWidget.  It 
> appears as if rendering anti-aliased text to a transparent buffer 
> blends a white background color into the text outline -- see attached 
> screenshots.  It should be red background, black outline, gray text.  
> What I get is red background, whitish anti-aliasing (or 
> alpha-blending) halo around black outline, black outline, and gray text.
>
> I don't think the problem is with QPainter::drawText, because I see 
> the same whitish halo around bitmap subtitles which I render into the 
> same transparent QImage via QPainter::drawImage.  Also, if I use 
> QGLWidget as the base class the issue vanishes -- the anti-aliasing 
> halo only appears when using QOpenGLWidget.
>
> Is this a bug, or some secret setting I missed?
>
> Thank you,
>     Pavel.
>


Hmm, I tried making a sample app to reproduce the problem so I could 
file a bug report.  In the process I tried rendering the same overlay 
using QPainter::drawImage and it came out looking all right.  So, I 
stepped through QPainter code and noticed that it uses a different blend 
function from what I used.  In my OpenGL code I had

         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

While QPainter used

         glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);


I switched my code to use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) 
for rendering the overlay frame and the halo has vanished.  I still 
don't know why it looked good before when I used QGLWidget as the base 
class.  Well, at least my immediate problem is fixed.

     Pavel.




More information about the Interest mailing list