glDrawElements

[New - Windows 95, OEM Service Release 2]

The glDrawElements function renders primitives from array data.

void glDrawElements(

    GLenum mode,

 

    GLsizei count,

 

    GLenum type,

 

    const GLvoid *indices

 

   );

 

 

Parameters

mode

The kind of primitives to render. It can assume one of the following symbolic values: GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_TRIANGLES, GL_QUAD_STRIP, GL_QUADS, and GL_POLYGON.

count

The number of elements to be rendered.

type

The type of the values in indices. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.

indices

A pointer to the location where the indices are stored.

 

Remarks

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.

 

Error Codes

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.

 

See Also

glArrayElement, glBegin, glColorPointer, glDrawArrays, glEdgeFlagPointer, glEnd, glGetPointerv, glIndexPointer, glNormalPointer, glTexCoordPointer, glVertexPointer