在 Khronos OpenGL 2.1 Specs 中,他们说 glStencilMask 应该会影响 glClear 的操作,但是,在我的机器上,这似乎不是真的。
我目前得到的输出是:
Stencil value: (0,0) 0xff
我期望的输出是:
Stencil value: (0,0) 0xf0
这是我的代码:
void renderScene(void) {
unsigned char pix;
int i [4];
/* Clear the stencil buffer initially */
glClearStencil(0x0);
glClear(GL_STENCIL_BUFFER_BIT);
/* Applies the following: 1111 0000 & 1111 1111 */
glStencilMask(0xF0);
glClearStencil(0xFF);
glClear(GL_STENCIL_BUFFER_BIT);
glFlush();
glReadPixels(0,0,1,1,GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &pix);
printf("Stencil value (0,0): %x\n",pix);
}
int main(int argc, char **argv) {
// init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_STENCIL );
glutInitWindowPosition(500,500);
glutInitWindowSize(320, 320);
glutCreateWindow("Trial");
// register callbacks
glutDisplayFunc(renderScene);
// enter GLUT event processing cycle
glutMainLoop();
return 1;
}
(显然我正在执行各种其他图纸等,但这说明了我所看到的问题)