// 删除stencil buffer glDeleteRenderbuffers(1, &stencil_rboId);但实际测试,发现stencil buffer根本不起作用,下面是一个测试函数:void stencilRenderTest() { GLdouble dRadius = 0.1; // Initial radius of spiral GLdouble dAngle; // Looping variable float x = 100; float y = 100; float rsize = 25; // Clear blue window glClearColor(0.0f, 0.0f, 1.0f, 0.0f); // Use 0 for clear stencil, enable stencil test glClearStencil(0.0f); glEnable(GL_STENCIL_TEST); // Clear color and stencil buffer glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // All drawing commands fail the stencil test, and are not // drawn, but increment the value in the stencil buffer. glStencilFunc(GL_NEVER, 0x0, 0x0); glStencilOp(GL_INCR, GL_INCR, GL_INCR); // Spiral pattern will create stencil pattern // Draw the spiral pattern with white lines. We // make the lines white to demonstrate that the // stencil function prevents them from being drawn glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINE_STRIP); for(dAngle = 0; dAngle < 400.0; dAngle += 0.1) { glVertex2d(dRadius * cos(dAngle), dRadius * sin(dAngle)); dRadius *= 1.002; } glEnd(); // Now, allow drawing, except where the stencil pattern is 0x1 // and do not make any further changes to the stencil buffer glStencilFunc(GL_NOTEQUAL, 0x1, 0x1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // Now draw red bouncing square // (x and y) are modified by a timer function glColor3f(1.0f, 0.0f, 0.0f); glRectf(x, y, x + rsize, y - rsize);}stencil正确时,结果显示是一个蓝色背景,红色小矩形块,矩形内部可以看到圆弧,下图右。stencil不正确结果是蓝色背景同心圆环 以及一个矩形红色块,图左。 相关阅读:Ubuntu 13.04 安装 OpenGL http://www.linuxidc.com/Linux/2013-05/84815.htmOpenGL三维球体数据生成与绘制【附源码】 http://www.linuxidc.com/Linux/2013-04/83235.htmUbuntu下OpenGL编程基础解析 http://www.linuxidc.com/Linux/2013-03/81675.htm如何在Ubuntu使用eclipse for c++配置OpenGL http://www.linuxidc.com/Linux/2012-11/74191.htm《OpenGL超级宝典》学习笔记 http://www.linuxidc.com/Linux/2013-10/91414.htm