c++ - OS X 上的 OpenGL 版本支持

标签 c++ macos qt opengl

我尝试以现代管道实现的方式在 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 context 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

虽然我不确定这个的确切含义,从这个想法的源头所写的内容来看,似乎 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

最佳答案

似乎我不是唯一一个为这个 tutorial 苦苦挣扎的人,我找到了解决方案 here .尽管提到教程的源代码缺少绑定(bind) 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);

关于c++ - OS X 上的 OpenGL 版本支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19990405/

相关文章:

c++ - 标准随机函数不起作用 - Qt MinGw

c++ - QTreeView::scrollTo 不工作

c++ - 按下触摸屏会触发mousePressEvent,如何判断是鼠标点击还是触摸屏点击?

c++ - 发生内存不足错误时怎么办?

c++ - 如何在运行时获取多个对象之一的句柄?

c++ - pthread_create 参数传递错误

swift - 为什么我不能在 viewDidLoad() 中访问 NSTextField 对象

ios - 如何替换当前的 CALayer

c++ - Visual Studio 中的链接器库错误

swift - 在 macOS (Swift) 上获取 BSD 驱动器名称的最佳方法是什么?