I'd like to lay out some things I think I've learned, but am unsure about:
glGenBuffers
and glBufferData
.glVertexAttribPointer
, rather than glVertex
, glNormal
, etc..glDrawElements
can 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:
glEnableClientState
before calling glDrawElements
. Does this mean the man page is wrong or outdated?GL_VERTEX_ARRAY
would seem to be the thing you enable if you're going to use glVertexPointer
, and likewise you'd use GL_NORMAL_ARRAY
with glNormalPointer
, and so on. But if I'm not using those functions, and am instead using generic vertex attributes with glVertexAttribPointer
, then why would it be necessary to enable GL_VERTEX_ARRAY
?If GL_VERTEX_ARRAY is not enabled, no geometric primitives are constructed.
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, calling glVertex*()
not only sets the vertex position, it also causes the vertex to be sent with the other attributes. Calling glVertexAttrib*(0, ...)
does the same thing. That's why older versions require you to use either attribute 0 or GL_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.
Your first 3 points are correct. And to answer your last half of your question, do not use glEnableClientState
for modern OpenGL. Start coding!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With