Masking In iPhone OpenGL ES
I did a quick search for "masking" and couldn't find an existing thread, so I'm wondering if it's possible to do masking using the iPhone OpenGL ES API. I'm not sure if this requires a stencil buffer, which -- as I understand it -- is unavailable in the iPhone implementation.
What I'm trying to accomplish can best be described as what Quartz can do, as shown here: http://developer.apple.com/documentation...ion_6.html in the first section entitled "Masking an Image With an Image Mask".
I'm not looking for anyone to tell me exactly how to do this, if it is indeed possible to do it at all. Just looking for a pointer to the general area in which I should explore.
What I'm trying to accomplish can best be described as what Quartz can do, as shown here: http://developer.apple.com/documentation...ion_6.html in the first section entitled "Masking an Image With an Image Mask".
I'm not looking for anyone to tell me exactly how to do this, if it is indeed possible to do it at all. Just looking for a pointer to the general area in which I should explore.
The alpha test, depth test, and stencil test stages in OpenGL(ES) provide a way to throw away pixels before they get to the framebuffer. That gives you a hard, aliased mask.
For masking like Quartz, you want to use blending. Draw the mask into an alpha channel (either a texture, or the framebuffer's destination alpha) and set up the blend func to use it.
For masking like Quartz, you want to use blending. Draw the mask into an alpha channel (either a texture, or the framebuffer's destination alpha) and set up the blend func to use it.
Thanks for the information.
If you import an image format that already has transparency (like PNG) and turn on the OpenGL blend function, this will be done automatically for you.
demonpants Wrote:If you import an image format that already has transparency (like PNG) and turn on the OpenGL blend function, this will be done automatically for you.
Yes, the GLSprite sample application is a good example of this.
What I'm looking to do, though, is put an arbitrary mask at an arbitrary location over an image and have only the parts of the image that are covered by the mask "show through". Think of a "spotlight" effect:
- Your image is something like a landscape.
- Your mask is a simple filled circle.
- As you position the circular mask at various locations over the image, only the parts of the image within the mask will be displayed.
- Presto - instant spotlight effect!
It's the same thing. Put the image on texture unit 0. Put the spotlight mask on unit 1. Set up the texture coordinates to position the mask where you want. Modulate the two images, blend the result into the framebuffer.
arekkusu Wrote:It's the same thing. Put the image on texture unit 0. Put the spotlight mask on unit 1. Set up the texture coordinates to position the mask where you want. Modulate the two images, blend the result into the framebuffer.
Thank you for the additional pointers. I haven't had the time to look any further into this, but when I do, I'll take this information to heart.
BTW, I'm sure that I speak for many others in this forum who've come here seeking assistance, but I just wanted to thank you for sharing your OpenGL expertise and knowledge.
I appreciate that you're teaching us how to fish, and not just handing out fish.

Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
OpenGL Differences between iPhone Sim and Real iPhone | SparkyNZ | 5 | 9,923 |
Apr 13, 2011 11:40 AM Last Post: SparkyNZ |