使用 OpenGL 混合纹理以轻轻擦除 Alpha 值
我有一个基于 GLPaint 示例代码的小绘画应用程序。它运行良好。 我的问题是我需要实现一个“画笔”来擦除已经绘制的纹理。
我的目标是拥有一个边缘柔软的橡皮擦。现在,我只是采用了用于绘图的相同纹理,但将混合功能从 切换为
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
,
glBlendFunc(GL_ZERO, GL_ZERO);
结果是一个方形矩形橡皮擦。没关系,但这不是我真正想要的。 我需要柔和的边缘。我想制作圆形橡皮擦而不是正方形橡皮擦。
您知道如何实现这一目标吗? 或者您知道是否有办法创建我自己的自定义混合函数?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你知道纹理的背景颜色吗?如果是这样,您可以简单地在其上绘制背景,而不是“擦除”。这会更简单一些,因为您只需更改颜色而不更改混合模式。
如果您需要通过混合来完成此操作,请尝试:
这将使用完整 Alpha 区域中的零,并随着画笔的 Alpha 逐渐消失而淡回到现有颜色。
此页面包含可能模式的完整列表:
http://www.opengl.org/sdk/docs/man/xhtml /glBlendFunc.xml
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:
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