GLCOLORPOINTER(3G)

πŸ“¦ version 24.3.3, in opensuse-leap 16.0

πŸ’… GLCOLORPOINTER β€” bestie, it's in the 3G manual section and it's giving "define an array of colors" ✨

okay so picture this: you're out here rendering, and you need a whole ARRAY of colors, not just one sad little color. that's what glColorPointer is for. it tells OpenGL where your colors live and what shape they're in. let's get into it πŸŽ€


🌸 C SPECIFICATION 🌸

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

like yes bestie that's the whole signature, no notes πŸ‘‘


✨ PARAMETERS ✨

  • size β€” how many components per color. has to be 3 or 4, no in-between. the initial value is 4.
  • type β€” the data type of each color component in the array. the accepted symbolic constants are GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, GL_FLOAT, and GL_DOUBLE. the initial value is GL_FLOAT.
  • stride β€” the byte offset between consecutive colors. if stride is 0 (which is the initial value, btw), the colors are understood to be tightly packed in the array. the initial value is 0.
  • ptr β€” a pointer to the first component of the first color element in the array. literally just where it all starts 🫢

πŸ¦‹ DESCRIPTION πŸ¦‹

glColorPointer specifies the location and data of an array of color components to use when rendering. size says how many components per color, and it must be 3 or 4. type says the data type of each color component, and stride specifies the byte stride from one color to the next β€” which is the whole trick that lets vertices and attributes be packed into a single array, or stored in separate arrays. (single-array storage may be more efficient on some implementations; see glInterleavedArrays.) iykyk ✨

when a color array is specified, size, type, stride, and ptr are saved as client-side state.

to enable and disable the color array, call glEnableClientState and glDisableClientState with the argument GL_COLOR_ARRAY. if it's enabled, the color array is used when glDrawArrays, glDrawElements, glDrawRangeElements, or glArrayElement is called. that's the moment it actually does something, bestie πŸ’–


🌈 NOTES 🌈

  • glColorPointer is available only if the GL version is 1.1 or greater. no 1.0 girlies allowed, sorry 😭
  • the color array is initially disabled and isn't accessed when glArrayElement, glDrawArrays, glDrawRangeElements, or glDrawElements is called.
  • execution of glColorPointer is not allowed between the execution of glBegin and the corresponding execution of glEnd β€” but an error may or may not be generated. and if no error is generated? the operation is undefined. so like. don't. πŸ’€
  • glColorPointer is typically implemented on the client side.
  • color array parameters are client-side state, so they are NOT saved or restored by glPushAttrib and glPopAttrib. use glPushClientAttrib and glPopClientAttrib instead. this one trips people up fr fr πŸ™ˆ

πŸ“ ERRORS πŸ“

  • GL_INVALID_VALUE is generated if size is not 3 or 4.
  • GL_INVALID_ENUM is generated if type is not an accepted value.
  • GL_INVALID_VALUE is generated if stride is negative.

πŸ‘‘ ASSOCIATED GETS πŸ‘‘

  • 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
  • glGetPointerv with argument GL_COLOR_ARRAY_POINTER

🧚 SEE ALSO 🧚

  • glArrayElement(3G)
  • glDrawArrays(3G)
  • glDrawElements(3G)
  • glEdgeFlagPointer(3G)
  • glEnable(3G)
  • glGetPointerv(3G)
  • glIndexPointer(3G)
  • glInterleavedArrays(3G)
  • glNormalPointer(3G)
  • glPopClientAttrib(3G)
  • glPushClientAttrib(3G)
  • glTexCoordPointer(3G)
  • glVertexPointer(3G)

quick vibe check: glColorPointer only exists if your GL version is 1.1 or higher, and it's straight up undefined behavior if you sneak it in between glBegin and glEnd. the manpage is being so real about this one, so be real back 🫢

okay that's the whole page, no cap, every last flag and constant accounted for πŸ’– and for the sign-off: this one lives in the GLCOLORPOINTER(3G) section of the manual β€” and yeah, the source and date line is literally just the same GLCOLORPOINTER(3G) tag, no version number, no date, nothing. she's mysterious like that πŸ’…βœ¨ slay, go forth and pointer your colors πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from