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

↘锁芯ラ 提交于 2019-11-28 03:53:39

问题


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


回答1:


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...


来源:https://stackoverflow.com/questions/14474259/how-do-i-enable-multisampling-antialiasing-in-opengl-with-qt5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!