如何使用Qt5在OpenGL中启用多重采样(抗锯齿)? [英] How do I enable multisampling (antialiasing) in OpenGL with Qt5?

查看:1031
本文介绍了如何使用Qt5在OpenGL中启用多重采样(抗锯齿)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

花点时间找出答案.

技巧是像这样在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆