【问题标题】:How to mask OpenGL quad with another quad如何用另一个四边形掩盖 OpenGL 四边形
【发布时间】: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);

我怎样才能使它在此之前绘制的任何内容都只会遮盖前一个四边形?

【问题讨论】:

    标签: opengl mask


    【解决方案1】:

    如果您想将渲染限制在矩形区域,则可以使用Scissor Test
    必须启用剪刀测试 (GL_SCISSOR_TEST) 并且可以通过glScissor 设置矩形区域。例如:

    glEnable(GL_SCISSOR_TEST);
    glScissor(x, w, width, height);   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多