I'm trying to put together a very basic OpenGL 3.2 (core profile) application. In the following code, which is supposed to create a VBO containing the vertex positions for a triangle, the call to glVertexAttribPointer
fails and raises the OpenGL error GL_INVALID_OPERATION
. What does this mean, and how might I go about fixing it?
GLuint vbo, attribLocation = glGetAttribLocation(...);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
GLfloat vertices[] = { 0, 1, 0, 1, 0, 0, -1, 0, 0 };
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(attribLocation);
// At this point, glGetError() returns GL_NO_ERROR.
glVertexAttribPointer(attribLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
// At this point, glGetError() returns GL_INVALID_OPERATION.
GL_INVALID_OPERATION
error is coming fromglVertexAttribPointer
? Remember: OpenGL stores the errors and returns them only when you callglGetError
. So if you're not regularly purging the error queue, you may be getting older errors. – WabbleglEnableVertexAttribArray
. – Wabblecout << glGetError() << endl;
around until I find the source of the error (I was planning to refactor once I get the basic demo done). I've added comments to the original question to show exactly where the error shows up. – FrierglGetError()
is 1282. The code is so short at the moment that I may as well upload it to GitHub - give me a few minutes and I'll do so. – Frier