opengl - 如何用另一个四边形掩盖 OpenGL 四边形
问题描述
我正在尝试显示一个四边形,但只有当它位于我知道其位置的另一个四边形上方时。我考虑过使用那个四边形作为另一个四边形的遮罩,但我不确定如何去做(我已经找到了这篇关于遮罩的帖子,但是在我的情况下,我没有遮罩纹理;我只知道遮罩区域的 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);
我怎样才能做到这一点,无论我在此之前绘制的是什么,它只会掩盖前一个四边形?
解决方案
如果要将渲染限制为矩形区域,则可以使用Scissor Test。
必须启用剪刀测试 ( GL_SCISSOR_TEST
),并且可以通过 设置矩形区域glScissor
。例如:
glEnable(GL_SCISSOR_TEST);
glScissor(x, w, width, height);
推荐阅读
- sql - 选择“第二”最高的记录
- react-native - 身份服务器重定向到 React Native 错误
- javascript - 离子载玻片固定在中心
- git - 合并最后一个共同祖先受变基影响的分支
- php - 将连接数据合并到一个文件中
- java - Windows 上的外部 application.properties 问题
- azure-webjobs - Azure WebJob:我正在从 Web 作业调用 sql server 存储过程
- twitter-bootstrap - “aria-disabled”有什么作用?
- rust - 如何将切片写入文件?
- netlogo - 如何将列表(和其他信息)从父模型全局变量传递到 Netlogo 的 LevelSpace 中的子模型全局变量