How do I enable multisampling (antialiasing) in OpenGL with Qt5?
Asked Answered
D

1

8

How do I enable multisampling when I create the window? How should I initialize OpenGL to match?

Desdamona answered 23/1, 2013 at 7:11 Comment(0)
D
14

Took me a while to figure this one out.

The trick is to use a QSurfaceFormat in your QWindow's constructor like so:

setSurfaceType(QWindow::OpenGLSurface);
QSurfaceFormat format;
format.setSamples(4);    // Set the number of samples used for multisampling
setFormat(format);       // Note we set the format on the window...
create();                // Create the window

context = new QOpenGLContext(this);
context->setFormat(format);    // ...and set the format on the context too
context->create();

And later, when initialising OpenGL:

glEnable(GL_MULTISAMPLE);    // This seems to be the default given the configuration above, but just in case that's not universal...
Desdamona answered 23/1, 2013 at 7:11 Comment(2)
really strange, what is the point in setting it on the QOpenGLContext if QWindow will just do its own thingBathulda
@paulm: No idea, I just fiddled with stuff until it worked ;-)Desdamona

© 2022 - 2024 — McMap. All rights reserved.