如何在Qt5的OpenGL中启用多重采样(抗锯齿)?

时间:2013-01-23 07:11:16

标签: opengl qt5 multisampling

创建窗口时如何启用多重采样?我应该如何初始化OpenGL以匹配?

1 个答案:

答案 0 :(得分:10)

我花了一些时间来解决这个问题。

诀窍是在QSurfaceFormat的构造函数中使用QWindow,如下所示:

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时:

glEnable(GL_MULTISAMPLE);    // This seems to be the default given the configuration above, but just in case that's not universal...