返回首页

这是一个如代码

void display (void) {

 

     glClearStencil(0); //clear the stencil buffer

     glClearDepth(1.0f);

     glClearColor (1.0,1.0,1.0,1);

     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |GL_STENCIL_BUFFER_BIT);

     glLoadIdentity();

     glTranslatef(0, 0, -10);

     //start

     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); //disable the color mask

     glDepthMask(GL_FALSE); //disable the depth mask



     glEnable(GL_STENCIL_TEST); //enable the stencil testing



 

     glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF);

     glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); //setthe stencil buffer to replace our next lot of data



     floor(); //set the data plane to be replaced



     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); //enablethe color mask

     glDepthMask(GL_TRUE); //enable the depth mask



     glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF);

     glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //set the stencilbuffer to keep our next lot of data



     glDisable(GL_DEPTH_TEST); //disable depth testing of thereflection

     glPushMatrix();

     glScalef(1.0f, -1.0f, 1.0f); //flip the reflection vertically



     glTranslatef(0,2,0); //translate the reflection onto the drawing plane

     glRotatef(angle,0,1,0); //rotate the reflection

     square(); //draw the square as our reflection

     glPopMatrix();

     glEnable(GL_DEPTH_TEST); //enable the depth testing

     glDisable(GL_STENCIL_TEST); //disable the stencil testing



    //end



    glEnable(GL_BLEND); //enable alpha blending

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //set the blending function



     floor(); //draw our bench

     glDisable(GL_BLEND); //disable alpha blending



     glRotatef(angle,0,1,0); //rotate our square

     square(); //draw our square



    glutSwapBuffers();

    angle++;

 }
为什么我们一件事之前禁用深度测试,呈现方形的反射吗?

回答

评论会员: 时间:2