2013-11-14 127 views
1

我尝试使用现代管道实现的方式在OS X 10.9上用Qt(v5.1.1)编写OpenGL项目。但是,我遇到一些问题,例如从教程中重建程序。 http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_QtOpenGL版本在OS X上的支持

简单的三角形不显示,但没有警告,程序本身出现。我怀疑我的mac可能不支持GLSL。所以我寻找一种方法来打印一些信息。我发现有类似问题的人是这样做的。

#include <QApplication> 
#include <QGLFormat> 
#include "glwidget.h" 

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

    QGLFormat mGlFormat; 
    mGlFormat.setVersion(3, 3); 
    mGlFormat.setProfile(QGLFormat::CoreProfile); 
    mGlFormat.setSampleBuffers(true); 

    qDebug() << "OpenGL context QFlags " << mGlFormat.openGLVersionFlags(); 
    qDebug() << "OpenGL context " << mGlFormat; 

    GLWidget mWidget(mGlFormat); 
    mWidget.show(); 

    qDebug() << "OpenGL context" << mWidget.format(); 
    qDebug() << "Driver Version String:" << glGetString(GL_VERSION); 

    return mApplication.exec(); 
} 

我得到了一个结果。

OpenGL上下文QFlags QFlags(为0x1 | 0X2 |为0x4 | 0x8中| 0×10 |为0x20 | 0x40的|×1000 |为0x2000 | 0x4000的| 0x8000)时

OpenGL上下文QGLFormat(选项QFlags(为0x1 | 0X2 |为0x4 | 0x20 | 0x80 | 0x200 | 0x400),plane 0,depthBufferSize -1,accumBufferSize -1,stencilBufferSize -1,redBufferSize -1,greenBufferSize -1,blueBufferSize -1,alphaBufferSize -1,samples -1,swapInterval -1,majorVersion 3 ,minorVersion 3,简档1)

OpenGL上下文QGLFormat(选项QFlags(为0x1 | 0X2 |为0x4 |为0x20 | 0x80的|为0x200 | 0x400的),平面0,depthBufferSize 1,accumBufferSize -1,stencilBufferSize 1,redBufferSize -1, greenBuff erSize -1,-1 blueBufferSize,alphaBufferSize -1,样品4,swapInterval -1,majorVersion 3,minorVersion 3,曲线1)

驱动程序版本字符串:0x10800e6be

即使我不知道这个的确切含义源于这个想法的源头,看起来0x8000意味着OpenGL 3.3首次被支持,但由于后面的标志只有0x400,版本支持在某种程度上会丢失。

我的图形卡是NVIDIA GeForce 9400M 256 MB,它应该支持OpenGL 3.3。 https://developer.apple.com/graphicsimaging/opengl/capabilities/

  • 这是否意味着我不能使用GLSL下,这些配置?
  • 如果是这样,是否有可能升级一些库或图形驱动程序?
  • 在不支持相同的计算机上启动时,使用核心配置文件的应用程序会发生什么情况?

类似的帖子 Can't set desired OpenGL version in QGLWidget

+0

C++ I/O流让我很烦。我非常肯定,您为版本字符串打印的值是字符串指向的地址,而不是实际的字符串。您可能需要将其转换为'(const char *)'或创建一个'std :: string'。 –

+0

只需在终端输入'glxinfo',它就会告诉你你的驱动支持什么。 – cmannett85

+0

@ cmannett85:这里的问题不是支持哪个版本,而是他实际得到的是什么版本。默认情况下,OS X将为您提供OpenGL 2.1上下文,除非您使用适当的像素格式标志来获取3.2核心上下文。 –

回答

3

看来我是不是唯一一个与此tutorial挣扎,我找到了解决办法here。尽管提到了教程的源代码缺少绑定VAO。

在initializeGL m_shader.setAttributeBuffer前补充一点:

uint vao; 

typedef void (APIENTRY *_glGenVertexArrays) (GLsizei, GLuint*); 
typedef void (APIENTRY *_glBindVertexArray) (GLuint); 

_glGenVertexArrays glGenVertexArrays; 
_glBindVertexArray glBindVertexArray; 

glGenVertexArrays = (_glGenVertexArrays) QGLWidget::context()->getProcAddress("glGenVertexArrays"); 
glBindVertexArray = (_glBindVertexArray) QGLWidget::context()->getProcAddress("glBindVertexArray"); 

glGenVertexArrays(1, &vao); 
glBindVertexArray(vao); 
+1

由于Qt 5.1存在VAO的包装: http://qt-project.org/doc/qt- 5.1/qtgui/qopenglvertexarrayobject.html – cguenther