-->

Eraser in OpenGL ES iphone

2020-07-22 09:20发布

问题:

i have two images which are overlapping on each other.(the way in which cards are placed on top of each other)

now if i move my finger over the top most image that portion of the image should become transparent.(opacity of that part should become 0).

i am new to OpenGL ES development.

kindly help me out or give me any suggestion to complete this functionality.

Thanks in advance

回答1:

You're going to need render-to-texture using Framebuffer Objects (FBOs). Render to the desired texture, but only to the alpha channel, which is done using glColorMask (With it you can mask all color channels except alpha), and then draw the pattern into the alpha channel, setting alpha to 0.0, then display the textures as normal.



回答2:

I just did something similar, and I found a solution in GLBlending:

if (eraseMode) {
    glBlendFunc(1.0,0.0);
}
else {
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}

Some cosmetics are needed around this, but it's a simple solution that fits basic needs.