【发布时间】:2019-10-28 00:43:53
【问题描述】:
我正在尝试显示一个四边形,但只有当它位于我知道位置的另一个四边形上方时。我曾考虑过使用该四边形作为另一个四边形的遮罩,但我不确定该怎么做(我已经发现 this 帖子谈到了遮罩,但是在我的情况下,我没有遮罩纹理;我只知道要屏蔽的区域的 X、Y、宽度和高度)。我目前找到的解决方案是使用glBlendFunc,它只有在我不渲染任何东西的情况下才有效,以后不会这样。
glBlendFunc(GL_ONE, GL_ZERO);
// draw the background quad, that is acting as the mask...
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ZERO);
// draw the background quad again, this time it will act as a mask...
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
// draw the quads that will be masked...
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // this is the blend func used for the rest of the rendering
在绘制每一帧之前,我还有一个清屏功能:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0,0,0,0);
我怎样才能使它在此之前绘制的任何内容都只会遮盖前一个四边形?
【问题讨论】: