我尝试以现代管道实现的方式在 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?
- 如果是这样,是否可以升级一些库或图形驱动程序?
- 在不支持核心配置文件的计算机上启动时,使用核心配置文件的应用程序会怎样?
最佳答案
似乎我不是唯一一个为这个 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/