I have a problem with my code: (OpenGL 4.1 Core Context, I'm using VertexArrayObjects)
//This is a member method, vertexArrayObject and vertexBufferObject are of course generated using glGenVertexArrays & glGenBuffers
glBindVertexArray(vertexArrayObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 8, 0);
Draw::debugLogGLError(); // OpenGL Error #0
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 8, (void*)(sizeof(float) * 3));
Draw::debugLogGLError(); // OpenGL Error #1282
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 8, (void*)(sizeof(float) * 6));
Draw::debugLogGLError(); // OpenGL Error #1282
glBindVertexArray(0);
Draw::debugLogGLError() simply prints out the latest error code to the console
void Draw::debugLogGLError(void){
std::cout << "OpenGL Error #" << glGetError() << std::endl;
}
If I remove the offsets (void*)(sizeof(float) * 3)
it will run just fine. So I'm assuming it's the (void*)
having problems. However it worked just fine before I started to implement this in a class. I might have missed some code
OS: Mavericks, HD5000, Clang compiler in Xcode
According to http://www.opengl.org/wiki/GLAPI/glVertexAttribPointer :
GL_INVALID_OPERATION is generated if size is GL_BGRA and type is not GL_UNSIGNED_BYTE, GL_INT_2_10_10_10_REV or GL_UNSIGNED_INT_2_10_10_10_REV.
GL_INVALID_OPERATION is generated if type is GL_INT_2_10_10_10_REV or GL_UNSIGNED_INT_2_10_10_10_REV and size is not 4 or GL_BGRA.
GL_INVALID_OPERATION is generated if type is GL_UNSIGNED_INT_10F_11F_11F_REV and size is not 3.
GL_INVALID_OPERATION is generated by glVertexAttribPointer if size is GL_BGRA and noramlized is GL_FALSE.
GL_INVALID_OPERATION is generated if zero is bound to the GL_ARRAY_BUFFER buffer object binding point and the pointer argument is not NULL.
GL_INVALID_OPERATION is generated if no vertex array object is bound.
The first 4 are obviously not the case so it must be one of the last 2. The last one can't be the case as it doesn't always throw the error, and the last one would. So the problem according to the wiki is:
GL_INVALID_OPERATION is generated if zero is bound to the GL_ARRAY_BUFFER buffer object binding point and the pointer argument is not NULL.
This would mean vertexBufferObject
in your code is 0 and thus not a valid buffer object. If this is not the case, I'd think you just stumbled upon a major driver bug.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.