OpenGL ES 1.0 中的“glTexEnv”、“glColor4x”和“glBlendFunc”有何关系?
我正在查看 SurfaceFlinger,即在 Android 中进行组合的代码,并且我很难理解一些 OpenGL ES 1.0 调用,因为我只编写了 ES 2.0 代码。
这是我感兴趣的代码片段:
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
它应该做的是将纹理混合到缓冲区中。
为什么需要 glTextEnvx
和 glColor4x
调用? glBlendFunc
不足以实现混合吗?
我知道我的问题很天真,但即使在阅读文档。
I'm looking at SurfaceFlinger, i.e. the the code that is doing the composition in Android, and I have trouble understanding some of the OpenGL ES 1.0 calls as I've only programmed ES 2.0 code.
Here goes the piece of code that interests me:
glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
What it is supposed to be doing is blending a texture into the buffer.
Why does one need the glTextEnvx
and glColor4x
calls? Isn't glBlendFunc
enough for achieving blending?
I know my question is naive, but I still don't understand what is glTexEnvx
for even after reading the docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
glTexEnv()
设置纹理环境模式。GL_REPLACE
告诉渲染器跳过当前颜色(例如,来自glColor4()
),而是告诉渲染器对每个相应像素使用纹理的颜色。如果您使用GL_MODULATE
而不是GL_REPLACE
,那么当渲染器设置像素的颜色。您的
glColor4()
调用不应执行任何可以在您的对象上看到的操作(使用GL_REPLACE
时)。关于
glBlendFunc()
参数:GL_ONE
使用来自传入基元的当前颜色,我们将其称为源。GL_ONE_MINUS_SRC_ALPHA
将目标(帧缓冲区中当前存储的像素)乘以(1 - 源 Alpha 值)。通常,当您不使用纹理时,当
glColor4()
包含 alpha 值(其中 1 等于完全不透明,0 等于完全透明)时,您可以从 color 基元实现透明效果。glTexEnv()
sets the texture environment mode.GL_REPLACE
tells the renderer to skip the current color (for example, fromglColor4()
) and instead tells the renderer to use your texture's colors for every corresponding pixel. If you, instead ofGL_REPLACE
, useGL_MODULATE
, then yourglColor4()
call will be included together with the texture's colors when the renderer sets a pixel's color.Your
glColor4()
call shouldn't be doing anything (when usingGL_REPLACE
) that can be seen on your object.About your
glBlendFunc()
arguments:GL_ONE
is using the current color that comes from your incoming primitive, which we call source.GL_ONE_MINUS_SRC_ALPHA
is multiplying the destination (which is the currently stored pixel in the frame buffer) by (1 - source alpha value).Normally, when you're not using textures, you achieve a transparent effect from color primitives when the
glColor4()
contains an alpha value where 1 equals fully opaque and 0 fully transparent.