在OpenGL ES中,如何加载具有透明像素的纹理? [英] In OpenGL ES, how do I load a texture that has transparent pixels?
本文介绍了在OpenGL ES中,如何加载具有透明像素的纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
然后正确显示?一个示例是将一个圆形的球放置在一个矩形中,同时能够在背景中看到另一个纹理.
And then have display correctly? An example would be having a round ball in a rectangle while being able to see another texture in the background.
目前,当我加载纹理时,源图像中的透明像素显示为黑色.
edit: At the moment, when I load the texture the transparent pixels from the source image are displayed as black.
推荐答案
适用于iPhone和N95:
For iPhone and N95 this works:
如果要从原始数据加载纹理,请将内部和源格式设置为GL_RGBA.
If you are loading texture from raw data, set internal and source format to GL_RGBA.
glTexImage2D(GL_TEXTURE_2D, 0,
GL_RGBA,
textureWidth,
textureHeight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
pointerToPixels);
然后在渲染时启用alpha混合:
And when rendering, enable alpha blend:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
这篇关于在OpenGL ES中,如何加载具有透明像素的纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文