IPhone: Layering a transparent openGL view on top of a UIView

iphoneopengltransparencyuiview

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.

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?

Thanks in advance.

Best Answer

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);

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! :)