I’d like to lay out some things I think I’ve learned, but am unsure about:
- VBOs are the way to go. They’re created with
glGenBuffersandglBufferData. - For maximum flexibility, it’s best to pass generic vertex attributes to shaders with
glVertexAttribPointer, rather thanglVertex,glNormal, etc.. glDrawElementscan be used with vertex buffers and an index buffer to efficiently render geometry with lots of shared vertices, such as a landscape mesh.
Assuming all of that is correct so far, here’s my question. All of the tutorials I’ve read about modern OpenGL completely omit glEnableClientState. But the OpenGL man pages say that without glEnableClientState, glDrawElements will do nothing:
http://www.opengl.org/sdk/docs/man/xhtml/glDrawElements.xml
The key passage is: “If GL_VERTEX_ARRAY is not enabled, no geometric primitives are constructed.”
This leads me to the following questions:
- None of the tutorials use
glEnableClientStatebefore callingglDrawElements. Does this mean the man page is wrong or outdated? GL_VERTEX_ARRAYwould seem to be the thing you enable if you’re going to useglVertexPointer, and likewise you’d useGL_NORMAL_ARRAYwithglNormalPointer, and so on. But if I’m not using those functions, and am instead using generic vertex attributes withglVertexAttribPointer, then why would it be necessary to enableGL_VERTEX_ARRAY?
That’s because the man page is wrong. The man page covers GL 2.1 (and it’s still wrong for that), and for whatever reason, the people updating the man page refuse to update the older GL versions for bug fixes.
In GL 2.1, you must use either generic attribute index 0 or
GL_VERTEX_ARRAY. In GL 3.1+, you don’t need to use any specific attribute indices.This is because, in GL versions before 3.1, all array rendering functions were defined in terms of calls to
glArrayElement, which used immediate mode-based rendering. That means that you need something to provoke the vertex. Recall that, in immediate mode, callingglVertex*()not only sets the vertex position, it also causes the vertex to be sent with the other attributes. CallingglVertexAttrib*(0, ...)does the same thing. That’s why older versions require you to use either attribute 0 orGL_VERTEX_ARRAY.In GL 3.1+, once they took out immediate mode, they had to specify array rendering differently. And because of that, they didn’t have to limit themselves to using attribute 0.
If you want API docs for core GL 3.3 works, I suggest you look at the actual API docs for core GL 3.3. Though to be honest, I’d just look at the spec if you want accurate information. Those docs have a lot of misinformation in them. And since they’re not actually wiki-pages, that information never gets corrected.