views:

709

answers:

2

Hello,

I've got an EAGLContext drawing into a CAEAGLLayer (via the standard GLGravityView example in the iPhone SDK).

What I'm trying to do is place my view on top of another view and use what I render in OpenGL to mask the underlying view.

Let's say the bottom view is a picture of a flower and I put my OpenGL view on top and I set the OpenGL clear-color to opaque black and then render my sphere. I want the sphere to cut through the black, exposing only a circular section of the flower picture. Even better would be to show both the sphere (as translucent) and the flower, cutting through the black.

I've called

glView.backgroundColor = [UIColor clearColor];
glClearColor(0.0, 0.0, 0.0, 1.0);

when I set up the view the and called

glColor4f( 1.0, 1.0, 1.0, 0.5 );

just before rendering the sphere.

It just makes the sphere off-white and doesn't show the underlying flower. I'm not too surprised by this.

Does anyone know how to create a mask instead?

Thank you for your help.

A: 

I've done something similar using just the "EAGLayer" or whatever it's called. Just draw the background first then draw more things on top. This worked because the tapping functionality of the bottom "layer" was either none or minimal. When I wanted tapping functionality in the bottom "layer" I just looked for taps near certain xy coords (as opposed to dragging/dropping buttons like you would with a real layer.)

It really depends on what you want to do with the bottom layer. If all you want is the flower pic then my approach works. If you want to drag/drop more complex UI controls then my approach won't work.

MrDatabase
+1  A: 

You've probably given up by now, but just in case...

I think your glClearColor(0.0, 0.0, 0.0, 1.0) should be glClearColor(0.0, 0.0, 0.0, 0.0) since you want to clear the view to "transparent black" with Alpha=0 rather than "opaque black" with Alpha = 1.

You should also make sure your OpenGL view isn't marked as opaque.

David Maymudes
Yep - this was the solution for me
Chaos