The glColorMask function enables and disables writing of frame-buffer color components.

void glColorMask(
  GLboolean red,    
  GLboolean green,  
  GLboolean blue,   
  GLboolean alpha   


red, green, blue, alpha
Specify whether red, green, blue, and alpha can or cannot be written into the framebuffer. The default values are all GL_TRUE, indicating that the color components can be written.


The glColorMask function specifies whether the individual color components in the framebuffer can or cannot be written. If red is GL_FALSE, for example, no change is made to the red component of any pixel in any of the color buffers, regardless of the drawing operation attempted.

Changes to individual bits of components cannot be controlled. Rather, changes are either enabled or disabled for entire color components.

The following functions retrieve information related to glColorMask:

glGet with argument GL_COLOR_WRITEMASK

glGet with argument GL_RGBA_MODE

Error Codes

The following is the error code generated and its condition.

Error code Condition
GL_INVALID_OPERATION glColorMask was called between a call to glBegin and the corresponding call to glEnd.


  Windows NT/2000: Requires Windows NT 3.5 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

glBegin, glColor, glDepthMask, glEnd, glGet, glIndex, glIndexMask, glStencilMask


Community Additions