OpenGL 3.2 コードを Windows から OS/X 10.8 に (GLFW コア プロファイルを使用して) 移植しようとしていますが、glDrawElements を呼び出すと INVALID_OPERATION (glError()) が発生します。glDrawArrays 関数は正常に動作するため、シェーダーは正常に初期化されます。
次のスニペットは、私が何をしているかをよく説明しています。私が間違っていることについて何か考えはありますか?
struct Vertex {
vec2 position;
vec3 color;
};
void display() {
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
mat4 projection = Ortho2D(-15.0f, 15.0f, -15.0f, 15.0f);
glUniformMatrix4fv(projectionUniform, 1, GL_TRUE, projection);
glBindVertexArray(shapeVertexArrayBuffer);
mat4 modelView;
// upper left
modelView = Translate(-7,+7,0);
glUniformMatrix4fv(modelViewUniform, 1, GL_TRUE, modelView);
glDrawArrays(GL_TRIANGLE_FAN, 0, rectangleSize); // renders correctly
// upper right
modelView = Translate(+7,+7,0);
glUniformMatrix4fv(modelViewUniform, 1, GL_TRUE, modelView);
GLuint indices[6] = {0,1,2,3,4,0};
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices); //INVALID_OPERATION
glfwSwapBuffers();
}
void loadGeometry() {
vec3 color(1.0f, 1.0f, 0.0f);
Vertex rectangleData[rectangleSize] = {
{ vec2( 0.0, 0.0 ), color },
{ vec2( 5.0, -5.0 ), color },
{ vec2( 5.0, 0.0 ), color },
{ vec2( 0.0, 5.0 ), color },
{ vec2(-5.0, 0.0 ), color },
{ vec2(-5.0, -5.0 ), color }
};
shapeVertexArrayBuffer = loadBufferData(rectangleData, rectangleSize);
}
GLuint loadBufferData(Vertex* vertices, int vertexCount) {
GLuint vertexArrayObject;
glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(positionAttribute);
glEnableVertexAttribArray(colorAttribute);
glVertexAttribPointer(positionAttribute, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)0);
glVertexAttribPointer(colorAttribute , 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *)sizeof(vec2));
return vertexArrayObject;
}