如何在 OpenGL ES 1.1 (iPhone) 中以编程方式对纹理对象进行 Alpha 淡入淡出
我在 iPhone 上使用 OpenGL ES 1.1 已有 10 个月了,在那段时间里,我无法完成一项看似简单的任务:以编程方式淡化纹理对象。为了简单起见:我如何在代码控制下对一个应用了纹理(带有 alpha)的简单 2D 三角形进行 alpha 淡入淡出。我想在场景上淡入/淡出它,而不是简单的彩色背景。到目前为止,我要做的唯一技术是创建一个纹理,其上有多个预褪色的纹理副本。 (恶心)
举个例子,我无法使用 Apple 的 GLSprite 示例代码作为起点来做到这一点。它已经使用具有自己的 Alpha 的纹理对四边形进行了纹理化。我想让那个对象淡入淡出。
I've been using OpenGL ES 1.1 on the iPhone for 10 months, and in that time there is one seemingly simple task I have been unable to do: programmatically fade a textured object. To keep it simple: how can I alpha fade, under code control, a simple 2D triangle that has a texture (with alpha) applied to it. I would like to fade it in/out while it is over a scene, not a simple colored background. So far the only technique I have to do this is to create a texture with multiple pre-faded copies of the texture on it. (Yuck)
As an example, I am unable to do this using Apple's GLSprite sample code as a starting point. It already textures a quad with a texture that has its own alpha. I would like to fade that object in and out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许我没有理解你的意思,但对我来说这似乎微不足道,而且我已经在我的应用程序中成功做到了这一点。方法是:
glEnable(GL_BLEND)
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
glColor4f(r * a, g * a , b * a, a)
混合函数适用于 porter-duff over 使用预乘颜色/纹理。
GL_TEXTURE_ENV_MODE
必须设置为GL_MODULATE
,但这是默认值。Maybe I'm not getting you right, but to me it seems trivial and I've been doing it my apps successfully. The way to go is:
glEnable(GL_BLEND)
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
glColor4f(r * a, g * a , b * a, a)
The blend function is for porter-duff over using premultiplied colors/textures. The
GL_TEXTURE_ENV_MODE
must be set toGL_MODULATE
, but that's the default.尼古拉的解决方案是正确的;请忽略我在苹果论坛上所说的话。由于纹理是预乘的,因此每个顶点的颜色也应该是预乘的。您应该使用 GL_ONE 而不是 GL_SRC_ALPHA,并执行以下操作:
Nikolai's solution is correct; please ignore what I said on the Apple forums. Since the texture is pre-multiplied, the per-vertex color should be too. You should use GL_ONE rather than GL_SRC_ALPHA, and do this: