OpenGL学习记录(一)

有关depth test / culling

Depth testing is an effective technique for hidden surface removal, and OpenGL has functions that do this for you behind the scenes. The concept is simple: When a pixel is drawn, it is assigned a value (called the z value) that denotes its distance from the viewer's perspective. Later, when another pixel needs to be drawn to that screen location, the new pixel's z value is compared to that of the pixel that is already stored there. If the new pixel's z value is higher, it is closer to the viewer and thus in front of the previous pixel, so the previous pixel is obscured by the new pixel. If the new pixel's z value is lower, it must be behind the existing pixel and thus is not obscured. This maneuver is accomplished internally by a depth buffer with storage for a depth value for every pixel on the screen

Culling is the term used to describe the technique of eliminating geometry that we know will never be seen. By not sending this geometry to your OpenGL driver and hardware, you can make significant performance improvements. One culling technique is backface culling, which eliminates the backsides of a surface.

以下是对相关数据的测试
前提: 

设置为外表面顺时针,顺时针为front,(即外表面为Front)椎体未作任何旋转是顶尖向外

       glFrontFace(GL_CW);

if(bCull)

              glEnable(GL_CULL_FACE);

       else

              glDisable(GL_CULL_FACE);

 

      //启动深度测试

       if(bDepth)

              glEnable(GL_DEPTH_TEST);

       else

              glDisable(GL_DEPTH_TEST);

 

       if(bOutline)

              glPolygonMode(GL_FRONT,GL_LINE);

       else

              glPolygonMode(GL_FRONT,GL_FILL);

           

 
            

 (1)        

int  bCull=0,bDepth=0,bOutline=1;

…….

           glRotatef(-110,1.0f,0.0f,0.0f);(沿x轴顶尖上旋110)    

              

         由第一幅图的绕行知椎体的右部显现的是前面的外面,而bOutline=1,外面为line,所以在右部有一弧形痕迹。而左部显现的是后面的内面。


   (2)  int bCull=0,bDepth=1,bOutline=0;          

            

       这图我仍然未明白为何会这样?????bOutline=0,而且bDepth=1,(和(5)比较就会觉得很奇怪)为什么前面的面无法显现???

  (3) int bCull=1,bDepth=1,bOutline=1;

             


  (4)int bCull=1,bDepth=0,bOutline=1; 

          


    (5) int bCull=1,bDepth=1,bOutline=0;  /  int bCull=1,bDepth=0,bOutline=0;

            


  (6) int bCull=0,bDepth=0,bOutline=0; 

          

  从第一幅图的绕行方向可以得出这结果(由于没有深度测试,锥右半部显前,锥左半部显后)


7int bCull=0,bDepth=1,bOutline=1;

          

posted @ 2009-02-16 17:45  大Vin  阅读(809)  评论(0编辑  收藏  举报