混合纹理以使用OpenGL轻柔地擦除alpha值 [英] Blending a texture to erase alpha values softly with OpenGL
问题描述
我有一个基于GLPaint示例代码的小涂料应用程序。它工作正常。
我的问题是我需要实现一个刷子来擦除已经绘制的纹理。
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);
到
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?
推荐答案
你知道吗?背景颜色的纹理?如果是这样,您可以简单地在其上绘制背景,而不是擦除。这会更简单,因为你只会更改颜色而不是混合模式。
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);
这将使用完全alpha的零区域,并作为画笔的淡入淡出现有颜色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.
此页面包含可能模式的完整列表:
http://www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml
This page contains a full list of possible modes: http://www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml
这篇关于混合纹理以使用OpenGL轻柔地擦除alpha值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!