如何在 OpenGL ES 1.1 (iPhone) 中以编程方式对纹理对象进行 Alpha 淡入淡出

发布于 2024-08-07 08:22:25 字数 297 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

同尘 2024-08-14 08:22:25

也许我没有理解你的意思,但对我来说这似乎微不足道,而且我已经在我的应用程序中成功做到了这一点。方法是:

  1. 启用纹理和所需的一切
  2. 启用混合:glEnable(GL_BLEND)
  3. 选择混合模式glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
  4. 设置要混合的颜色: glColor4f(r * a, g * a , b * a, a)
  5. 绘制几何图形

混合函数适用于 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:

  1. enable texturing and everything you need
  2. enable blending: glEnable(GL_BLEND)
  3. select a blend mode glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
  4. set a color to blend with: glColor4f(r * a, g * a , b * a, a)
  5. draw your geometry

The blend function is for porter-duff over using premultiplied colors/textures. The GL_TEXTURE_ENV_MODE must be set to GL_MODULATE, but that's the default.

春夜浅 2024-08-14 08:22:25

尼古拉的解决方案是正确的;请忽略我在苹果论坛上所说的话。由于纹理是预乘的,因此每个顶点的颜色也应该是预乘的。您应该使用 GL_ONE 而不是 GL_SRC_ALPHA,并执行以下操作:

glColor4f(1., 1., 1., myDesiredAlpha);
glColor4f(myDesiredAlpha, myDesiredAlpha, myDesiredAlpha, myDesiredAlpha);

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:

glColor4f(1., 1., 1., myDesiredAlpha);
glColor4f(myDesiredAlpha, myDesiredAlpha, myDesiredAlpha, myDesiredAlpha);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文