1

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

简单的三角形没有出现,但是没有警告并且程序本身出现了。我怀疑我的 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|0x10|0x20|0x40|0x1000|0x2000|0x4000|0x8000)

OpenGL context QGLFormat(options 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 , profile 1 )

OpenGL context QGLFormat(options 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 4 , swapInterval -1 , majorVersion 3 , minorVersion 3 , profile 1 )

Driver Version String: 0x10800e6be

Even though I am not sure about the exact meaning of this, derived from what was written at the source of this idea, it seems that the 0x8000 meant that OpenGL 3.3 is first supported but since later flags are only 0x400 the version support is lost somehow along the way.

My graphic card is NVIDIA GeForce 9400M 256 MB which should support OpenGL 3.3. https://developer.apple.com/graphicsimaging/opengl/capabilities/

  • Does that mean I am not able to use the GLSL under these configurations?
  • If so, is it possible to upgrade some library or graphics driver?
  • What happens to applications using the core profile when started on a computer that does not support the very same?

Similar post Can't set desired OpenGL version in QGLWidget

4

1 回答 1

3

It seems I was not the only one struggling with this tutorial, and I found the solution here. Even though it is mentioned the source code of the tutorial is missing to bind the VAO.

Add this in initializeGL before 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);
于 2013-11-15T15:33:06.647 回答