Please consider the following images for the illustration:
Initially I fill the whole screen/stage with individual Images until the screen turns pink. Each blob of pink colour is an individual Image actor that I add to the stage.
Now I want to implement the touchDown method in such a way that each time the user touches the screen, it erases a part of that Image where the touch event took place. However, that touch event should not effect other Images/actors/TextureRegions that are behind or above the pink blob actors. How am I supposed to achieve this in libgdx using OpenGL ES? Please help me in this regard.
I found this link which explains how to modify a TextureRegion but I don't know how I am going to achieve solution for my problem using the technique explained in this blog. Here is the link
Could you use FBO's and a stencil buffer?
Setup an FBO for your "pink" layer and a stencil buffer for it. On touch down, draw your touch as a mask to the pink FBO's stencil buffer. Now when you draw the pink FBO, the areas you touched wont be rendered so you'll be able to see the background FBO behind it.
This link http://www.opengl.org/archives/resources/faq/technical/rasterization.htm, section 14.050 tells you how to setup a stencil buffer:
You can set up OpenGL state as follows:
glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 0x1, 0x1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
Subsequent rendering will set a 1 bit in the stencil buffer for every pixel rendered.
You may have to fiddle with things so your masking comes out the right way (masks where you did touch, not where you didn't.)
来源:https://stackoverflow.com/questions/10373847/producing-eraser-effects-using-libgdx-and-opengl-es