How to enable multisampling Anti-Aliasing with QOpenGLWidget?
-
I have a QDockWidget that contains a QOpenGLWidget inside it.
I'm trying to set up AA in the GL viewport, but nothing I tried so far worked.Right now I'm trying to set up the surface format in the widget's constructor, like so:
QSurfaceFormat format; format.setRenderableType(QSurfaceFormat::OpenGL); format.setProfile(QSurfaceFormat::CoreProfile); format.setVersion(4, 1); format.setSamples(16); setFormat(format);
Then, in the initializeGL function, I've added the line
glEnable(GL_MULTISAMPLE);
However, it doesn't work. No Anti-Aliasing.
I tried several other approaches, including creating the GL context myself and setting the format on it or setting up application flags and the default surface format, but none of them worked either.I'm quite at a loss here, and I'm probably missing something simple since the consensus points to
format.setSamples(16);
as the crucial element, but as I said, it doesn't work for me.Any ideas what I'm doing wrong here?
-
I'd like to give a modest contribution here. I also had an issue with multisampling.
I was on Windows 10, using Qt 5.15 with PyQt5, and my graphics driver was Intel(R) UHD Graphics 630.
There were two things I did to fix it - creating a default QSurfaceFormat BEFORE creating QApplication and asking for an OpenGL version higher than 3.3 with a compatibility profile. Apparently, asking OpenGL 3.3 version with a compatible profile didn't have multisampling. As soon as I asked for 4.0 compatibility or higher, it worked. Don't know if some other version + profile might have a similar issue.
One more thing I've observed was that QtGui.QSurfaceFormat.defaultFormat().samples() and QtOpenGLWidget.format().samples() would return 0, no matter what was set before. I'm not sure now, but I think it was 0 as soon as the widget was shown. Before you show it, it did say the right number of samples.
I hope I've maybe helped somebody and didn't confuse anybody.