I don't get it. Everything was working fine earlier, now the following code fragment won't even work. According to gDEbugger, I get a GL_INVALID_OPERATION on the glVertexAttribPointer() call. But I don't see anything wrong with it.
The weird thing is, it starts working fine if I change my OpenGL context to 3.1 (instead of 3.2) and backward compatible (instead of forward compatible).
Am I missing something obvious, or has my computer gone crazy?
If you are using core profile on GL 3.2, then you must use VAO when you call glBindBuffer and glVertexAttribPointer.
VAO? Vertex arrays? I thought vertex arrays were older and got replaced by VBOs. Weird. Do you have any links where I can get more info on these functions requiring VAOs? The OpenGL man page doesn't mention it as far as I can tell.
Where is your glewInit() call? It should be before glBindBuffer and after glfwOpenWindow
Woops, looks like I accidentally cut that out while trying to find the minimum amount of code to reproduce the problem. Even with that line, I get the same result. I've edited my code snippet.
[quote name='V-man' timestamp='1315138606' post='4857452']
If you are using core profile on GL 3.2, then you must use VAO when you call glBindBuffer and glVertexAttribPointer.
VAO? Vertex arrays? I thought vertex arrays were older and got replaced by VBOs. Weird. Do you have any links where I can get more info on these functions requiring VAOs? The OpenGL man page doesn't mention it as far as I can tell.
[/quote]
To clarify the terms here:
Vertex arrays (VA) is the mechanism by which you store objects in arrays and draw vertices in batches. Vertex arrays are most certainly not old and replaced. It is, in fact, the only way to draw something today.
Vertex buffer object (VBO) is an object that stores vertex array data. It is the OpenGL equivalent to, for example, new[] or malloc. Its only purpose is to provide storage for your vertex arrays.
Vertex array objects (VAO) is an object that stores VBO bindings. You can see it as an object that stores calls to glVertexAttribPointer and glEnableVertexAttribArray so you can quickly re-bind and enable a set of arrays by binding the VAO object, instead of binding several VBO objects and resetting pointers for ever attribute.
All three of these are quite useless on their own today, but they all exist to work together. For example, in previous versions you could use VAs alone by passing pointers to your own memory. That is not possible anymore, and now you need store the vertex arrays in a VBO instead.
The functions for VAO you want to look for are glGenVertexArrays and glBindVertexArray.
@Brother Bob
Thanks for the clarification! I don't know why the OpenGL documentation is so vague, the man pages for those two functions you mention say almost nothing.