OpengL裁剪

在OpenGL中,裁剪用到glScissor:

void glScissor(
  GLint x,
  GLint y,
  GLsizei width,
  GLsizei height
);

Parameters
x, y
The lower-left corner of the scissor box. Initially (0,0).
width, height
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.
Remarks
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.
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.
When the scissor test is disabled, it is as though the scissor box includes the entire window.
The following functions retrieve information related to glScissor:
glGet with argument GL_SCISSOR_BOX
glIsEnabled with argument GL_SCISSOR_TEST

例子:

void CShape3D::drawTriangle(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glLineWidth(2.0f);
    glBegin(GL_TRIANGLE_STRIP);
        glColor3f(0.0f, 1.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glVertex3fv(vTanglePoint[0]);
        glVertex3fv(vTanglePoint[1]);
        glVertex3fv(vTanglePoint[2]);
        glVertex3fv(vTanglePoint[3]);
    glEnd();

    glEnable(GL_SCISSOR_TEST);  
    glScissor(0,400 / 4, 400, 400 / 2);  
    glClear(GL_COLOR_BUFFER_BIT);  
    
    glFlush();
    glDisable(GL_SCISSOR_TEST);
    glutSwapBuffers();
}

cocos2dx的遮罩其实也可以利用这个来处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值