【发布时间】:2013-11-13 19:56:58
【问题描述】:
我正在尝试在 qt 5.1.1 中使用着色器使用 opengl 编写地图应用程序。 我能够使用 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);
}
就像我说的,这一切在我的 linux 机器上运行良好,所以我确信代码没有什么问题。我只需要知道如何告诉 qt 构建系统在 windows (7) 机器上选择正确的 opengl 驱动程序。显卡 Nvidia GT325m
【问题讨论】:
-
您可能需要将
#define GL_GLEXT_PROTOTYPES添加到包含它的文件中。 -
你能粘贴一个显示问题的最小 sn-p 吗?
-
@JesusRamos,我已经这样做了。似乎没有工作。顺便说一句,问题是opengl版本(正如Michael IV在其中一个答案中提到的那样)。我正在使用带有 mesa 驱动程序的 archlinux 的 qt5 版本。我终于用 glew 得到了我需要的东西。我的笔记本电脑太弱了,无法处理从源代码构建 qt。
-
从源代码构建 qt 只需要一段时间,我认为不会崩溃。
-
它不会崩溃。就像我说的,我的笔记本电脑太旧了,在构建时它会发热并关闭。