OpenGL ES 1: 雾和纹理透明度

huangapple go评论51阅读模式
英文:

OpenGL ES 1: Fog and texture transparency

问题

我有一些非常老的Android应用程序,使用OpenGL ES 1.x,我需要在Google Play上更新它们,以使它们在新设备上正常工作。在做了必要的更新,如弃用代码等之后,我发现在使用雾的地方,具有透明度的纹理现在不再起作用。透明的部分显示得很轻微。如果我关闭雾,一切都正常工作。

这在我部署应用程序时一切正常,并且在过去的几年里经过了测试而没有问题。但显然现在发生了一些变化。

有没有谁仍然了解OpenGL ES 1.x的人可以帮助解决这个问题吗?这是我的代码的一部分,应用雾然后绘制所有的四边形:

        gl.glFogf(GL10.GL_FOG_MODE, GL10.GL_LINEAR);
        gl.glHint(GL10.GL_FOG_HINT, GL10.GL_NICEST);
        gl.glFogf(GL10.GL_FOG_START, startZ);
        gl.glFogf(GL10.GL_FOG_END, endZ);
        gl.glFogfv(GL10.GL_FOG_COLOR, fColor, 0);
        gl.glEnable(GL10.GL_FOG);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

        super.drawSprites(gl);

        gl.glDisable(GL10.GL_FOG);

这是雾开启时呈现的示例,正如您所见,四边形的透明部分显示出来。

英文:

I have some very old android apps using OpenGL ES 1.x that I need to update in Google Play in order to make them work on newer devices. After doing the needed updates of deprecated code etc, I found that where I'm using fog, textures with transparency now no longer works. The transparent parts are showing slightly. If I turn off fog everything works fine though.

This was all working fine when I deployed the apps and has been tested through the years without issues. But apparently something has changed now.

Is there anyone that still has knowledge about OpenGL ES 1.x who can help with this? Here's the part of my code applying the fog and then drawing all the quads:

        gl.glFogf(GL10.GL_FOG_MODE, GL10.GL_LINEAR);
        gl.glHint(GL10.GL_FOG_HINT, GL10.GL_NICEST);
        gl.glFogf(GL10.GL_FOG_START, startZ);
        gl.glFogf(GL10.GL_FOG_END, endZ);
        gl.glFogfv(GL10.GL_FOG_COLOR, fColor, 0);
        gl.glEnable(GL10.GL_FOG);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

        super.drawSprites(gl);

        gl.glDisable(GL10.GL_FOG);

And here's an example of how it renders when fog is on, as you see the transparent parts of the quads are showing:
OpenGL ES 1: 雾和纹理透明度

答案1

得分: 0

看起来你缺少了 GL_ALPHA_TEST 以剔除透明片段,所以你会在每个精灵的透明部分捕捉到雾的颜色。

英文:

Looks like you are missing GL_ALPHA_TEST to cull the transparent fragments so you are picking up fog color on the transparent parts of each sprite.

答案2

得分: 0

这似乎是一个特定设备的问题。我的测试手机是三星Galaxy s22 ultra,在其他设备上进行测试时(包括s21 ultra),没有其他手机显示相同的错误。因此,我将将此标记为答案。感谢@solidpixel帮助进行调试。

英文:

This seems to be a device specific problem. My test phone was a Samsung Galaxy s22 ultra, and when testing on other devices (including the s21 ultra) no other phone shows the same error. So I will mark this as the answer. Thanks to @solidpixel for helping out with the debugging.

huangapple
  • 本文由 发表于 2023年2月16日 19:40:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471741.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定