4

シェーダーを使用して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);
}

私が言ったように、これはすべて私のLinuxボックスでうまく機能しているので、コードに大きな問題はないと確信しています. Windows(7)マシンで正しいopenglドライバーを選択するようにqtビルドシステムに指示する方法を知る必要があるだけです。グラフィックカード Nvidia GT325m

4

1 に答える 1

5

Qt 5 では、通常の方法では機能しません。問題は、事前にコンパイルされた Qt SDK (おそらく Web サイトから入手したもの) が、デフォルトで有効になっている GL レンダリングに GLES 2.0 バックエンドを使用していることです。つまり、glew ヘッダーは、qopenglfunction ヘッダーの同様の宣言に関連するあらゆる種類のエラーを取得します。残念ながら、opengl -desktop コマンドを使用して Qt ソースを再構築する必要があります。これにより、ES2.0 への依存が削除されます。もう 1 つの方法は、Qt 4.8 バージョンを使用することです。

于 2013-11-13T21:53:41.327 に答える