OpenGL纹理混合问题 [英] OpenGL texture blending problems

查看:185
本文介绍了OpenGL纹理混合问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenGL ES为iPad创建一个2D应用程序并且有一些问题绘制透明图像。

I'm creating a 2d application for the iPad using OpenGL ES and having some issue drawing transparent images.

我正在使用完全透明的png-24图像。我也在改变一些纹理的颜色,这些纹理是白色的,有些区域是透明的或半透明的。一切正常。

I'm using png-24 images with full transparency. I'm also changing the color of some of some textures, which are white with some areas transparent or semi-transparent. That all works fine.

然而,当我尝试设置其中一个纹理的alpha值时,它的效果并不正常。颜色太饱和了,如果alpha值= 0,我会在浅灰色背景上留下白色而不是透明的图像。当这样的透明图像在暗图像上时,暗图像变成与透明图像的颜色相似的颜色。

When I try to set the alpha value of one of these textures, however, it's not working quite right. The colors are much too saturated, and if the alpha value = 0, i'm left with a white rather than transparent image over a light grey background. When such a transparent image is over a dark image, the dark image becomes a color similar to color of the transparent image.

我尝试过很多参数组合 glTexEnvi glBlendFunc 但没有成功。

I've tried a many parameter combinations of the glTexEnvi and glBlendFunc with no success.

我'我对OpenGL知之甚少,所以如果有人有任何建议,那就太棒了。如果有任何细节可以帮助我,请告诉我。

I'm not very knowledgable about OpenGL, so if anyone has any suggestions, that would be great. Let me know if there are any details that would help.

谢谢。

这是OpenGL的初始化

Here is the initialization of OpenGL


    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    glDisable(GL_DEPTH_TEST);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnable(GL_TEXTURE_2D);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_BLEND);


推荐答案

感谢大家的投入。我想我找到了一个解决方案。

Thanks for everyone's input. I think I've found a solution.

问题在于纹理有预乘alpha但是应用纹理的多边形没有。使用 glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); 到位我只需要do是手动将多边形的R,G和B颜色值乘以alpha值,这样所有内容基本上都是使用预乘alpha并一致渲染。

The problem was that the textures had premultiplied alpha but the polygons the textures are being applied to did not. With glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); and glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); in place all I had to do was manually multiply the R, G, and B color values of the polygons by the alpha value so that everything is essentially using premultiplied alpha and renders consistently.

我是不确定这是否是最有效的解决方案,但它似乎完美地工作到目前为止,只需要在我的图像渲染类中添加几行代码,以便在不透明度发生变化时更新颜色值。

I'm not sure if this is the most efficient solution, but it seems to work perfectly so far and it was just a matter of adding a few lines of code to my image rendering class to update the color values whenever the opacity is changed.

wooo

这篇关于OpenGL纹理混合问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆