我正在研究用C编写的基于OpenGL的UI.我有一个控件层次结构 - 在较大控件的可滚动区域内的小方形2D框.在小盒子内部绘制3D场景.必须在小的2D框内剪切3D场景,并且必须在较大的区域内剪切小的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();
}
Run Code Online (Sandbox Code Playgroud)
有一种简单的方法可以做我想要的吗?显然我也可以计算小型和大型剪刀盒的交叉点,或者我可以更仔细地剪辑/投影我的3D场景,但这比OpenGL调用更复杂.也许还有另一种方法可以做到这一点,我不知道. …