Tuesday, May 31, 2011

glDepthMask example c c++ objc java

Name

glDepthMask - enable or disable writing into the depth buffer

C Specification

void glDepthMask(GLboolean flag)

Parameters

flag
Specifies whether the depth buffer is enabled for writing. If flag is GL_FALSE, depth buffer writing is disabled, otherwise it is enabled. The initial value is GL_TRUE.

Description

glDepthMask specifies whether the depth buffer is enabled for writing. If flag is GL_FALSE, depth buffer writing is disabled. Otherwise, it is enabled. Initially, depth buffer writing is enabled.

Notes

glDepthMask does not affect glClear.

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

glClear, glColorMask, glDepthFunc, glDepthRange, glStencilMask


Example
----------------------------------------------------------------------------
void display(void)
{
  int pass;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();

      glEnable(GL_ALPHA_TEST);
      pass = 2;

{
      glDisable(GL_ALPHA_TEST);
      pass = 0;
    }

 
   glRotatef(view_h, 0, 1, 0);
    glRotatef(view_v, 1, 0, 0);

    do {
      if (pass == 2) {
        glAlphaFunc(GL_EQUAL, 1);
        glDepthMask(GL_TRUE);
        pass--;
      } else if (pass != 0) {
        glAlphaFunc(GL_NOTEQUAL, 1);
        glDepthMask(GL_FALSE);
        pass--;
     }
      draw_engine_pole();

      glPushMatrix();
        glTranslatef(0.5, 1.4, 0.0);
        draw_cylinder_head();
      glPopMatrix();

      glPushMatrix();
        glTranslatef(0.0, -0.8, 0.0);
        draw_crank();
      glPopMatrix();
    } while (pass > 0);

    glDepthMask(GL_TRUE);
    glutSwapBuffers();
  glPopMatrix();

}