本文整理汇总了C++中GLWindow::setSurfaceType方法的典型用法代码示例。如果您正苦于以下问题:C++ GLWindow::setSurfaceType方法的具体用法?C++ GLWindow::setSurfaceType怎么用?C++ GLWindow::setSurfaceType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLWindow
的用法示例。
在下文中一共展示了GLWindow::setSurfaceType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
auto glversion = gl::getAvailableVersion();
auto major = GL_GET_MAJOR_VERSION(glversion);
auto minor = GL_GET_MINOR_VERSION(glversion);
if (glversion < GL_MAKE_VERSION(4, 1)) {
MessageBoxA(nullptr, "Interface requires OpenGL 4.1 or higher", "Unsupported", MB_OK);
return 0;
}
QGuiApplication app(argc, argv);
bool quitting = false;
// FIXME need to handle window closing message so that we can stop the timer
GLWindow* window = new GLWindow();
window->create();
window->show();
window->setSurfaceType(QSurface::OpenGLSurface);
window->setFormat(getDefaultOpenGLSurfaceFormat());
bool contextCreated = false;
QTimer* timer = new QTimer();
QObject::connect(timer, &QTimer::timeout, [&] {
if (quitting) {
return;
}
if (!contextCreated) {
window->createContext();
contextCreated = true;
}
if (!window->makeCurrent()) {
throw std::runtime_error("Failed");
}
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
window->swapBuffers();
window->doneCurrent();
});
// FIXME need to handle window closing message so that we can stop the timer
QObject::connect(&app, &QCoreApplication::aboutToQuit, [&] {
quitting = true;
QObject::disconnect(timer, &QTimer::timeout, nullptr, nullptr);
timer->stop();
timer->deleteLater();
});
timer->setInterval(15);
timer->setSingleShot(false);
timer->start();
app.exec();
return 0;
}