OpenGL blending seems to be weirdly different after switching from QGLWidget to QOpenGLWidget

257 Views Asked by At

I'm switching my 3D modeling app from using Qt's QGLWidget to QOpenGLWidget, since the latter is the newer better version going forward for using OpenGL in Qt. However, after having switched, OpenGL blending seems to be behaving differently. When I draw the polygon/subd lines over the 3D models, here using a straight black color with .5 (i.e. 50%) in the color source alpha, the older QGLWidget blends as expected while the newer QOpenGLWidget somehow draws lines that are actually lighter than the color they're drawing over/blending with:

Older QGLWidget, blending black lines at 50% looks as expected: Older QGLWidget, blending black lines at 50% looks as expected Newer QOpenGLWidget, somehow turning black lines into lighter lines when blending at 50%: Newer QOpenGLWidget, somehow turning black lines into lighter lines when blending at 50%

You can see a similar problem in the red grid line on the floor, how in the latter case it's drawing a deep red color as a light pink when using blending.

I'm using simple blending code, essentially the following:

glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0, 0, 0, .5);
...
//then draw lines

I'm guessing it has something to do with something different in the framebuffer's alpha channel or something like that, any ideas? Oh, this is on Mac, I haven't tried it on Windows yet.

1

There are 1 best solutions below

1
Thomas On

Putting this in main before I create the QApplication seems to fix it, no idea why:

QSurfaceFormat myFormat = QSurfaceFormat::defaultFormat();
myFormat.setSamples(1);
QSurfaceFormat::setDefaultFormat(myFormat);