如何使用 Qt5 在 OpenGL 中启用多重采样(抗锯齿)? [英] How do I enable multisampling (antialiasing) in OpenGL with Qt5?
本文介绍了如何使用 Qt5 在 OpenGL 中启用多重采样(抗锯齿)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在创建窗口时启用多重采样?我应该如何初始化 OpenGL 以匹配?
How do I enable multisampling when I create the window? How should I initialize OpenGL to match?
推荐答案
我花了一段时间才弄明白.
Took me a while to figure this one out.
诀窍是在 QWindow
的构造函数中使用 QSurfaceFormat
,如下所示:
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();
然后,在初始化 OpenGL 时:
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...
这篇关于如何使用 Qt5 在 OpenGL 中启用多重采样(抗锯齿)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文