/* Main display routine. Clears the drawing buffer and if transparency is
   set, displays the model twice, 1st time accepting those fragments with 
   a ALPHA value of 1 only, then with DEPTH_BUFFER writing disabled for 
   those with other values. */
void 
display(void)
{
  int pass;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
    if (transparent) {
      glEnable(GL_ALPHA_TEST);
      pass = 2;
    } else {
      glDisable(GL_ALPHA_TEST);
      pass = 0;
    }

    /* Rotate the whole model */
    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();
}
예제 #2
0
/* Main display routine. Clears the drawing buffer and if transparency is
   set, displays the model twice, 1st time accepting those fragments with 
   a ALPHA value of 1 only, then with DEPTH_BUFFER writing disabled for 
   those with other values. */
void 
display(void)
{
  int pass;

#ifdef STEREO
  int i;

  /* enclose original rendering code in 2-pass loop */
  for (i=0; i<2; i++)
  {
  /* adjust projection matrix for stereo viewpoint */
  if (bStereoEnabled) {
	  glDrawBuffer((i==0) ? GL_BACK_LEFT : GL_BACK_RIGHT);
	  glMatrixMode(GL_PROJECTION);
	  glPushMatrix();
	  glLoadMatrixf((i==0) ? &mProjectionLeft : &mProjectionRight);
	  glMatrixMode(GL_MODELVIEW);
	  }
#endif

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
	if (transparent) {
	  glEnable(GL_ALPHA_TEST);
	  pass = 2;
	} else {
	  glDisable(GL_ALPHA_TEST);
	  pass = 0;
	}

	/* Rotate the whole model */
	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);
  glPopMatrix();

#ifdef STEREO
  /* render twice for stereo, or once for mono */
  if (bStereoEnabled) {
	  glFlush();
	  glMatrixMode(GL_PROJECTION);
	  glPopMatrix();
	  glMatrixMode(GL_MODELVIEW);
	  }
  else
	  break;
  } /* for loop */
#endif

  glutSwapBuffers();
}