glColorPointer

The glColorPointer function defines an array of colors.

void glColorPointer(
  GLint size,
  GLenum type,
  GLsizei stride,
  const GLvoid *pointer
);

Parameters

size
The number of components per color. The value must be either 3 or 4.
type
The data type of each color component in a color array. Acceptable data types are specified with the following constants: GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, or GL_DOUBLE.
stride
The byte offset between consecutive colors. When stride is zero, the colors are tightly packed in the array.
pointer
A pointer to the first component of the first color element in a color array.

Remarks

The glColorPointer function specifies the location and data format of an array of color components to use when rendering. The stride parameter determines the byte offset from one color to the next, enabling the packing of vertex attributes in a single array or storage in separate arrays. In some implementations, storing vertex attributes in a single array can be more efficient than the use of separate arrays.

Enabled the color array by specifying the GL_COLOR_ARRAY constant with glEnableClientState. Calling glArrayElement, glDrawElements, or glDrawArrays uses the color array that is thus enabled. By default, the color array is disabled. The glColorPointer calls cannot by entered in display lists.

When you specify a color array using glColorPointer, the values of all the function's color array parameters are saved in a client-side state, and you can cache static array elements. Because the color array parameters are in a client-side state, glPushAttrib and glPopAttrib do not save or restore the parameters' values.

Although specifying the color array within glBegin and glEnd pairs does not generate an error, the results are undefined.

The following functions retrieve information related to the glColorPointer function:

glIsEnabled with argument GL_COLOR_ARRAY

glGet with argument GL_COLOR_ARRAY_SIZE

glGet with argument GL_COLOR_ARRAY_TYPE

glGet with argument GL_COLOR_ARRAY_STRIDE

glGet with argument GL_COLOR_ARRAY_COUNT

glGetPointerv with argument GL_COLOR_ARRAY_POINTER

Error Codes

The following are the error codes generated and their conditions.

Error code Condition
GL_INVALID_VALUE size was not 3 or 4.
GL_INVALID_ENUM type was not an accepted value.
GL_INVALID_VALUE stride or count was negative.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in Gl.h.
  Library: Use Opengl32.lib.

See Also

glArrayElement, glBegin, glDrawArrays, glEdgeFlagPointer, glEnableClientState, glEnd, glGet, glGetString, glGetPointerv, glIndexPointer, glIsEnabled, glNormalPointer, glPopAttrib, glPushAttrib, glTexCoordPointer, glVertexPointer


  

Community Additions

Show: