iphone - 使用深度缓冲区而不是模板缓冲区进行裁剪

标签 iphone ios opengl-es

在旧的 iOS 设备上,模板缓冲区不可用。剪刀也只适用于简单的矩形。对于更一般的裁剪,我们可以使用深度缓冲区吗?为简单起见,假设我们仅在二维中绘图。

此外,我的具体要求是能够旋转裁剪矩形。

最佳答案

是的,绝对是。例如。 (在我输入时编码):

glEnable(GL_DEPTH_TEST); // to enable writing to the depth buffer
glDepthFunc(GL_ALWAYS);  // to ensure everything you draw passes
glDepthMask(GL_TRUE);    // to allow writes to the depth buffer
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
                         // so that whatever we draw isn't actually visible

glClear(GL_DEPTH_BUFFER_BIT); // for a fresh start

/* here: draw geometry to clip to the inside of, e.g. at z = -2 */

glDepthFunc(GL_GREATER); // so that the z test will actually be applied
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
                         // so that pixels are painted again...
glDepthMask(GL_FALSE);  // ... but don't change the clip area

/* here: draw the geometry to clip inside the old shape at a z further than -2 */

因此,主要特点是:

  • 深度测试可以设置为始终通过
  • 即使设置了其他缓冲区值也可以禁用颜色绘图

关于iphone - 使用深度缓冲区而不是模板缓冲区进行裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5809585/

相关文章:

ios - 将 accessToken 存储在 iOS 钥匙串(keychain)中

ios - OpenGLES 帧缓冲区问题

opengl - OpenGL 对四元数的支持是什么?

ios - 自动旋转模态视图

ios - Objective-C:让 AVPlayer 在所有应用程序 Controller 中播放(或在后台播放)

linux - 通过 SSH 连接 OpenGL 时出现问题

iphone - 录制iPhone应用程序视频(无需模拟器)

ios - 如何计算特定 iPhone 上的像素到点的转换?

ios - 从 UIScrollView 获取可见的标签文本

iphone - 如何使用PhoneNumberFormatter类在UITextField中格式化电话号码?