我正在开发一个用 C 语言编写的基于 OpenGL 的用户界面。我有一个控件层次结构——在一个更大控件的可滚动区域内的小方形 2D 框。在小盒子里面绘制了 3D 场景。 3D 场景必须在小 2D 框内剪裁,小 2D 框必须在较大区域内剪裁。
glScissor()
显然是确保绘图发生在所需区域内的候选者。问题是我不能同时为大区域调用 glScissor()
,然后为较大剪裁区域内的子区域再次调用 glScissor()
。
演示我想要的示例代码:
void drawBigBox() {
glScissor( ... ); //set the bounds of the larger region
for each little box {
//these might be anywhere, but they should only be visible if inside the glScissor bounds
drawLittleBoxes();
}
}
void drawLittleBoxes() {
//draw only inside little box -- Whoops! This replaces the big box bounds!
//How can I meet this constraint while retaining the outer scissor region?
glScissor( ... );
draw3dScene();
}
有没有一种简单的方法可以做我想做的事?显然,我还可以计算小型和大型剪刀盒的交集,或者我可以更仔细地剪辑/投影我的 3D 场景,但这比 OpenGL 调用更复杂。也许还有另一种我不知道的方法可以做到这一点。
谢谢!
最佳答案
为此,使用模板缓冲区可能更容易。您可以在写入四边形时使用 INCR 来增加模板缓冲区值,并且在绘制时将测试设置为 EQUAL 或 GEQUAL 以仅写入模板缓冲区具有最高值的位置,因此它只会写入受约束的区域所有当前裁剪区域。要在绘制层次结构时删除它们,请使用 DECR 再次删除它们。 这样你也可以有非矩形的裁剪区域。
关于c - 带 OpenGL 的嵌套剪刀盒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7465360/