Wednesday, June 1, 2011

glColorMask example c c++ java objc

Name
glColorMask - enable and disable writing of color buffer components

C Specification

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

Parameters

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

Description

glColorMask specifies whether the individual components in the color buffer can or cannot be written. If red is GL_FALSE, for example, no change is made to the red component of any pixel in the color buffer, regardless of the drawing operation attempted, including glClear.
Changes to individual bits of components cannot be controlled. Rather, changes are either enabled or disabled for entire color components.

Copyright

Copyright © 2003 Silicon Graphics, Inc.
This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

See Also

glClearglColorglColorPointerglDepthMaskglStencilMask



Example

_checkGLErrors();
m_fbo.AttachTexture( GL_COLOR_ATTACHMENT0_EXT, m_tempTexture.glTarget, m_tempTexture.glTexID );
assert( m_fbo.IsValid() );
m_fbo.Bind();
_checkGLErrors();
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glClear( GL_COLOR_BUFFER_BIT );
// C = srcC * srcA + dstC = C * A + C’ * A’ + …
// A = srcA + dstA = A + A’ + A” + …
glBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE );
glBlendEquationSeparate( GL_FUNC_ADD, GL_FUNC_ADD );
for( Primitive::PList::const_iterator i = m_primitives.begin() ; i != m_primitives.end() ; i++ ) {
(*i)->bake();
}
m_fbo.Unattach( GL_COLOR_ATTACHMENT0_EXT );
m_fbo.Disable();
_checkGLErrors();
// divide color by alpha
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
—> glDisable(GL_BLEND); <---
glBlendFunc( GL_ONE, GL_ZERO );
procInf.imageOp( m_tempTexture, m_transferFunction, m_program );
// render again this time to figure out the max alpha value
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, 1.0, 0.0, 1.0, -1.0, 1.0 );
m_fbo.AttachTexture( GL_COLOR_ATTACHMENT0_EXT, m_transferFunction.glTarget, m_transferFunction.glTexID );
assert( m_fbo.IsValid() );
m_fbo.Bind();
_checkGLErrors();
---> glEnable( GL_BLEND ); <---
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE );
glBlendEquation( GL_MAX );
for( Primitive::PList::const_iterator i = m_primitives.begin() ; i != m_primitives.end() ; i++ ) {
(*i)->bake();
}
m_fbo.Disable();