在qopenglfunctions.h中找不到glGenBuffers,glBindBuffer等

Ric*_*wan 4 c++ opengl qt glsl

我试图在使用着色器的opengl渲染的qt 5.1.1中编写一个地图应用程序.我能够使用Glew显示顶点.但是我想使用qopenglfunctions.h中提供的函数.奇怪的是,即使我包含这个文件,我也没有在这个范围内声明glGenBuffers.当我打开qopenglfunctions.h时,它就坐在那个文件中!有人遇到过这个奇怪的问题吗?代码相当长.但我添加了一些抛出链接器错误.

initializeGLFunctions();
this->program=program;

glGenVertexArrays(1,&mapVAO); //This is where the linker throws an error
glBindVertexArray(mapVAO);

// Generate 2 VBOs
glGenBuffers(2, mapBuffer);
initMapBoundary();


void GeometryEngine::initMapBoundary()
{
     GLfloat mapSize=5.0f;
  VertexData boundary[] = {
    // Vertex data for face 0
    {QVector3D(-mapSize, -mapSize,  1.0), QVector2D(0, 0)},  // v0
    {QVector3D( mapSize, -mapSize,  1.0), QVector2D(20.0,0/*0.33, 0.0*/)}, // v1
    {QVector3D(-mapSize,  mapSize,  1.0), QVector2D(0,20/*0.0, 0.5*/)},  // v2
    {QVector3D( mapSize,  mapSize,  1.0), QVector2D(20.0,20.0/*0.33, 0.5*/)}, // v3
};


GLushort indices[] = {
    0,  1,  2,  3,
};


// Transfer vertex data to VBO 0
glBindBuffer(GL_ARRAY_BUFFER, mapBuffer[0]);
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(VertexData), boundary, GL_STATIC_DRAW);

// Transfer index data to VBO 1
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mapBuffer[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4 * sizeof(GLushort), indices, GL_STATIC_DRAW);

// Offset for position
quintptr offset = 0;

// Tell OpenGL programmable pipeline how to locate vertex position data
int vertexLocation = program->attributeLocation("a_position");
program->enableAttributeArray(vertexLocation);
// program->setAttributeBuffer(vertexLocation,GL_FLOAT,offset,3);
glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);

// Offset for texture coordinate
offset += sizeof(QVector3D);

// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
int texcoordLocation = program->attributeLocation("a_texcoord");
program->enableAttributeArray(texcoordLocation);
glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);
//program->setAttributeBuffer(texcoordLocation,GL_FLOAT,offset,2);
}
Run Code Online (Sandbox Code Playgroud)

就像我说的,所有这些在我的linux盒子上运行正常,所以我确信代码没有什么大不了的.我只需要知道如何告诉qt构建系统在windows(7)机器上选择正确的opengl驱动程序.显卡Nvidia GT325m

Mic*_* IV 5

使用Qt 5,它不会以常规方式为您服务.问题是,预编译的Qt SDK(您可能从他们的网站获得)使用GLES 2.0后端默认启用GL渲染.这意味着,您的glew标头将获得与qopenglfunction标头中的类似声明相关的所有类型的错误.不幸的是,您将不得不使用opengl -desktop命令重建Qt源,这将取消对您的ES2.0依赖.另一种方法是使用Qt 4.8版本.