最初の頂点がどこにあっても常に (0,0,0) に描画されるという問題がありました (他のすべての位置は正しい)。「init」関数の間違いだと思います。私が使用するポジションは次のとおりです。
positions.push_back( glm::vec3(-0.5f , -0.5f , 0.0f ) );
positions.push_back( glm::vec3( 0.0f , 0.5f , 0.0f ) );
positions.push_back( glm::vec3( 0.5f , -0.5f , 0.0f ) );
私の「init」機能:
// generate buffers
glGenVertexArrays(1, &this->VAO);
glGenBuffers(1, &this->VBO);
glGenBuffers(1, &this->EBO);
glBindVertexArray(this->VAO);
// fill buffers with data
glBindBuffer(GL_ARRAY_BUFFER, this->VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3) * this->positions.size(), &this->positions[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * this->indices.size(), &this->indices[0], GL_STATIC_DRAW);
// linking vertex attributes
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
// unbind (only) VAO
glBindVertexArray(0);
そして私の「レンダリング」機能(VAOをレンダリングするためだけで、シェーダーはありません):
glBindVertexArray(this->VAO);
glDrawElements(GL_TRIANGLES, this->numElements, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
また、「glVertexAttribPointer」関数で「stride」と「pointer」の値を調整しようとしましたが、うまくいきませんでした。