现在的位置: 首页 > 综合 > 正文

OpengL裁剪

2019年11月12日 ⁄ 综合 ⁄ 共 1938字 ⁄ 字号 评论关闭

在OpenGL中,裁剪用到glScissor:

  1. void glScissor(  
  2.   GLint x,  
  3.   GLint y,  
  4.   GLsizei width,  
  5.   GLsizei height  
  6. );  

  1. Parameters  
  2. x, y  
  3. The lower-left corner of the scissor box. Initially (0,0).  
  4. width, height  
  5. The width and height of the scissor box. When an OpenGL context is first attached to a window, width and height are set to the dimensions of that window.  
  6. Remarks  
  7. The glScissor function defines a rectangle, called the scissor box, in window coordinates. The first two parameters, x and y, specify the lower-left corner of the box. The width and height parameters specify the width and height of the box.  
  8. The scissor test is enabled and disabled using glEnable and glDisable with argument GL_SCISSOR_TEST. While the scissor test is enabled, only pixels that lie within the scissor box can be modified by drawing commands. Window coordinates have integer values at the shared corners of framebuffer pixels, so glScissor(0,0,1,1) allows only the lower-left pixel in the window to be modified, and glScissor(0,0,0,0) disallows modification to all pixels in the window.  
  9. When the scissor test is disabled, it is as though the scissor box includes the entire window.  
  10. The following functions retrieve information related to glScissor:  
  11. glGet with argument GL_SCISSOR_BOX  
  12. glIsEnabled with argument GL_SCISSOR_TEST  

例子:

  1. void CShape3D::drawTriangle(void) {  
  2.     glClear(GL_COLOR_BUFFER_BIT);  
  3.     glLineWidth(2.0f);  
  4.     glBegin(GL_TRIANGLE_STRIP);  
  5.         glColor3f(0.0f, 1.0f, 0.0f);  
  6.         glClear(GL_COLOR_BUFFER_BIT);  
  7.         glVertex3fv(vTanglePoint[0]);  
  8.         glVertex3fv(vTanglePoint[1]);  
  9.         glVertex3fv(vTanglePoint[2]);  
  10.         glVertex3fv(vTanglePoint[3]);  
  11.     glEnd();  
  12.   
  13.     glEnable(GL_SCISSOR_TEST);    
  14.     glScissor(0,400 / 4, 400, 400 / 2);    
  15.     glClear(GL_COLOR_BUFFER_BIT);    
  16.       
  17.     glFlush();  
  18.     glDisable(GL_SCISSOR_TEST);  
  19.     glutSwapBuffers();  

抱歉!评论已关闭.