iPhone:在UIView上面分层透明的openGL视图? [英] iPhone: Layering a transparent openGL view on top of a UIView?

查看:110
本文介绍了iPhone:在UIView上面分层透明的openGL视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发iPhone应用程序,我在常规UIView上有一个openGL视图渲染。它正在工作,但我似乎无法让openGL视图有一个透明的背景,显示下面的UIView。相反,我得到一个大黑盒子。

I am working on iPhone app and I have an openGL view rendering on top of a regular UIView. It's working, but I can't seem to get the openGL view to have a transparent background that shows the UIView underneath. Instead, I get a big black box.

我尝试将背景颜色设置为UIColor clearColor,我将opaque设置为NO,我将glClearColor设置为0.0 ,0.0,0.0,0.0。

I have tried setting the background color to UIColor clearColor, I've set opaque to NO, I've set glClearColor to 0.0,0.0,0.0,0.0.

我认为我误解/误用了与混合模式相关的东西,但我不确定。任何人都可以给我一些示例代码,说明如何执行此操作吗?

I think I'm misunderstanding/misusing something related to blend modes, but I'm not sure. Can anyone give me a bit of sample code which shows how to do this?

提前致谢。

推荐答案

以下是我必须做的工作:

Here's what I had to do to get this to work:

eaglLayer.opaque = NO;      
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

如果您正在做我正在做的事情并且正在尝试使用GLGravity演示进行测试,每次调用 drawView 时,会再次调用 glClearColor(0.0f,0.0f,0.0f,1.0f); - 所以一定要把它改成 glClearColor(0.0f,0.0f,0.0f,0.0f); 也是如此! :)

And incase you're doing what I was doing and are trying to test it with the GLGravity demo, there's another call to glClearColor(0.0f, 0.0f, 0.0f, 1.0f); every time drawView is called -- so make sure you change that one to glClearColor(0.0f, 0.0f, 0.0f, 0.0f); too! :)

这篇关于iPhone:在UIView上面分层透明的openGL视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆