The glDrawElements function renders primitives from array data.
void glDrawElements(
GLenum mode,
GLsizei count,
GLenum type,
const GLvoid *indices
);
The glDrawElements function enables you to specify multiple geometric primitives with very few function calls. Instead of calling an OpenGL function to pass each individual vertex, normal, or color, you can specify separate arrays of vertexes, normals, and colors beforehand and use them to define a sequence of primitives (all of the same type) with a single call to glDrawElements.
When you call the glDrawElements function, it uses count sequential elements from indices to construct a sequence of geometric primitives. The mode parameter specifies what kind of primitives are constructed, and how the array elements are used to construct these primitives. If GL_VERTEX_ARRAY is not enabled, no geometric primitives are generated.
Vertex attributes that are modified by glDrawElements have an unspecified value after glDrawElements returns. For example, if GL_COLOR_ARRAY is enabled, the value of the current color is undefined after glDrawElements executes. Attributes that aren't modified remain unchanged.
You can include the glDrawElements function in display lists. When glDrawElements is included in a display list, the necessary array data (determined by the array pointers and enables) is also entered into the display list. Because the array pointers and enables are client-side state variables, their values affect display lists when the lists are created, not when the lists are executed.
Note The glDrawElements function is only available in OpenGL version 1.1 or later.
The following are the error codes generated and their conditions.
Error Code | Condition |
---|---|
GL_INVALID_ENUM | mode was not an accepted value. |
GL_INVALID_VALUE | count was a negative value. |
GL_INVALID_OPERATION | glDrawElements was called between a call to glBegin and the corresponding call to glEnd. |
glArrayElement, glBegin, glColorPointer, glDrawArrays, glEdgeFlagPointer, glEnd, glGetPointerv, glIndexPointer, glNormalPointer, glTexCoordPointer, glVertexPointer