9

I have a little paint application which was based on the GLPaint sample code. It is working fine. My Problem is that I need to implement a "brush" that erases the textures which were already drawn.

My goal is to have an eraser which has soft edges. Right now I just took the same texture which I used for drawing but switched the blending functions from

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

to

glBlendFunc(GL_ZERO, GL_ZERO);

The result is a square rectangular eraser. That is ok but it's not what I actually want. I need soft edges. I want to make a round eraser not a square rectangular.

Do you have any guess how to achieve that? Or do you know if there is a way to create my own custom blending function?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Hung Dang
  • 105
  • 1
  • 6
  • I think you wanted something like this: http://stackoverflow.com/questions/10373847/producing-eraser-effects-using-libgdx-and-opengl-es which is actually my own problem and I am still stuck on how to achieve this. – Rafay May 01 '12 at 05:52

1 Answers1

12

Do you know the background color of the texture? If so, instead of "erasing", you could simply paint background over it. That would be somewhat simpler, as you would only change the color and not the blending mod.

If you need to do it with blending, try:

glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);

This will use the zero in area of full alpha, and fade back into the existing color as the brush's alpha fades off.

This page contains a full list of possible modes: http://www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml

ssube
  • 47,010
  • 7
  • 103
  • 140
  • The background is an image, so i can not paint over it. Do you have other solution? – Hung Dang Nov 02 '10 at 04:54
  • The blending function I suggested is worth a try, if that's available. If GL_ZERO/GL_ZERO worked, then using zero and the inverse alpha should as well. – ssube Nov 02 '10 at 04:57
  • I try the function glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA), but it even can not erase. – Hung Dang Nov 02 '10 at 05:02
  • I'm not sure why that would be. If `GL_SRC_ALPHA, GL_ONE` paints, then the inverse (`GL_ZERO, GL_ONE_MINUS_SRC_ALPHA`) should erase. Especially since you say `GL_ZERO, GL_ZERO` works. If you can't figure it out, I would recommend experimenting with different combinations and testing them with color combinations that are obviously visible. – ssube Nov 02 '10 at 19:00