2015-12-10 51 views
2

我一直在使用带QOpenGLWindow的着色器文件,并有版本330着色器,一切工作正常。 但是,想要切换Widget以便能够将其停靠在我的主窗口应用程序中。自那以后,我一直在努力寻找正确的环境。QOpenGLWidget QT请求上下文

我能够创建一个使用QGLWidget来绘图(这是我所看到的是不建议使用)是正确的:

QGLFormat format; 
format.setProfile(QGLFormat::CoreProfile); 
format.setVersion(3,3);                                            
QGLFormat::setDefaultFormat(format); 

当我做同样的事情用。然而QOpenGLWidget: 我得到

QOpenGLShader::compile(Vertex): ERROR: 0:1: '' : version '330' is not supported 

这是一些现有的合理方式,QGLFormat的管理不负责新类。

但是切换到新的类,并设置核心配置文件后:

QSurfaceFormat format; 
    format.setProfile(QSurfaceFormat::CoreProfile); 
    format.setVersion(3,3); 
    QSurfaceFormat::setDefaultFormat(format); 

我越来越迷恋:

0 libobjc.A.dylib     0x00007fff89f9a0dd objc_msgSend + 29 
1 libqcocoa.dylib     0x000000011085e3a3 QCocoaIntegration::createPlatformOpenGLContext(QOpenGLContext*) const + 83 
2 org.qt-project.QtGui   0x000000010d2c954a QOpenGLContext::create() + 74 
3 org.qt-project.QtWidgets  0x000000010cc35a6d QOpenGLWidgetPrivate::initialize() + 141 
4 org.qt-project.QtWidgets  0x000000010cc36e58 QOpenGLWidget::event(QEvent*) + 232 
5 org.qt-project.QtWidgets  0x000000010cbd632b QApplicationPrivate::notify_helper(QObject*, QEvent*) + 251 
6 org.qt-project.QtWidgets  0x000000010cbd9648 QApplication::notify(QObject*, QEvent*) + 8136 
7 org.qt-project.QtCore   0x000000010da59d83 QCoreApplication::notifyInternal(QObject*, QEvent*) + 115 
8 org.qt-project.QtWidgets  0x000000010cc18879 sendWindowChangeToTextureChildrenRecursively(QWidget*) + 73 
9 org.qt-project.QtWidgets  0x000000010cc03339 QWidget::setParent(QWidget*, QFlags<Qt::WindowType>) + 2217 
10 org.qt-project.QtWidgets  0x000000010cbf4569 QLayout::addChildWidget(QWidget*) + 201 
11 org.qt-project.QtWidgets  0x000000010cd1e740 QMainWindowLayout::setCentralWidget(QWidget*) + 32 
12 ultrahaptics.Optimus_gui  0x000000010cb27f74 MainWindow::MainWindow() + 580 
13 ultrahaptics.Optimus_gui  0x000000010cb2396b main + 59 

我使用OS X上的MacBook Pro。如果有人知道解决方法/理由评论会受到欢迎。

回答

0

你应该波纹管移动代码到main.cpp的文件:

QGLFormat format; 
format.setProfile(QGLFormat::CoreProfile); 
format.setVersion(3,3);                                            
QGLFormat::setDefaultFormat(format); 

你的main.cpp应该是长相:

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 

     QSurfaceFormat format; 
//  format.setDepthBufferSize(24); 
    // format.setStencilBufferSize(8); 

     format.setMajorVersion(3); 
     format.setMinorVersion(3); 
     format.setProfile(QSurfaceFormat::CoreProfile); 
     QSurfaceFormat::setDefaultFormat(format); 

    Dialog w; 
    w.show(); 

    return a.exec(); 
} 

可能需要QSurfaceFormat头文件添加到您的主的.cpp!

我希望这会有所帮助。

欢呼声, 奈

+0

谢谢,我会尽快检查一下。如果你可以如此善良,并提供信息为什么这样工作,我会接受答案。 – cerkiewny

1

我读的地方,如果你开发在OS X上你的OpenGL程序(无论你做什么平台使用:Qt Creator中,XCode的..),你将能够使用只有一个版本的OpenGL 2.1或4.1,默认版本通常是2.1 所以,通过使用setDefaultFormat,我们强制系统为我们初始化OpenGL 4.1。

我上传了一个如何在Mac上使用OpenGL 4.X的例子。

QOpenGLWidget_OpenGL4.1

享受