【发布时间】:2013-09-01 13:19:14
【问题描述】:
我正在尝试配置我的模板缓冲区,以便在启用时,它会在绘制的像素不透明时设置(从而创建光可以碰撞的像素图)。我所做的是:
glClearStencil(0); //clear stencil
glStencilFunc(GL_EQUAL, 0xFF, 0x000000FF); //only where alpha (mask : 0x000000FF) is 0xFF (opaque)
glStencilOp(GL_INCR, GL_KEEP, GL_KEEP); //increment if passes (if it is opaque)
render(); //withing this method I sometimes disable the whole thing to draw the floor, for example
然后,我使用以下代码进行测试:
/* TURN OFF STENCIL */
glEnable(GL_STENCIL_TEST); //re-enable
glStencilFunc(GL_EQUAL, 0, 1); //if the test is equal to 1
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //do not change stencil buffer
ImageInfo.drawColorSquare(0, 0, Configurations.SCREEN_WIDTH, Configurations.GAME_HEIGHT, Color.BLUE); //drwa blue square
glDisable(GL_STENCIL_TEST); //disable
但是,有两个问题:
- 它似乎没有忽略透明像素,因为它应该;
- 如果一个区域与另一个区域重叠,则会反转 - 例如,它设置为 1,然后在同一区域中绘制另一个区域,然后再次将其重置为 0。
我不知道为什么会这样。我猜我的面具可能有问题 - 我不确定 OpneGL 在颜色缓冲区中使用了多少像素。 此外,根据文档,GL_INCR 应该加到最大值,而不是返回。由于我的模板缓冲区大小是一位,它应该设置为 1,尝试再次增加,失败,并保持为 1(而不是重置)。
【问题讨论】:
-
glStencilFunc中的 mask 参数不是指颜色缓冲区中的像素值,而是指模板缓冲区中的值。您不能以这种方式使用模板缓冲区。 -
你是说没有办法只添加不透明的像素?我正在关注本教程:archive.gamedev.net/archive/reference/programming/features/… 我处于第一步,遇到了这个巨大的问题......
标签: opengl rendering lwjgl stencil-buffer