OpenGL ES 2.0 w/ GLKit Transparent Textures

I am trying to apply a texture (128x128 with a black arrow in the middle and the rest of the texture is transparent). My model contains vertices that also have color data. Before I apply the texture the model looks correct with each vertex containing the correct color information. Once I apply the texture, it shows up correctly with the arrows everywhere with the portions that should be transparent are transparent yet the model is also transparent. I want the texture to lay "on top" of the model and you should be able to see through the transparent portion of the texture and see the colors of the model underneath. See below for what I'm talking about. I have glEnable(GL_BLEND) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) added as well.

As you can see below, the first image is with the texture and the second image is without the texture. I want to be able to see the color data of the second image on the first image. What is the issue?

与纹理没有纹理


The Blend Function is generally used for overlapping semi-transparent polygons. From your description, I do not think it is relevant.

It sounds like you are asking to derive the output color from the alpha-weighted average of the vertex color and texture color. In a shader that would look something like this:

gl_FragColor = vec4(
  vertexColor.a * vertexColor.rgb + textureColor.a * textureColor.rgb, 1.0);

Using GLKit you may be able to achieve the desired effect with GLKBaseEffect but I have not tried it. Documentation points out you must enable GLKVertexAttribColor in addition to setting up texture coordinates. Given your images it seems you've done that, so you may need to write your own shader.


The ability to set the fragment color using GLKit relies on using the envMode property on GLKEffectPropertyTexture. This was a comment I posted earlier but am going to mark it as the answer now.

链接地址: http://www.djcxy.com/p/34010.html

上一篇: 全屏幕纹理iPhone OpenGL ES

下一篇: OpenGL ES 2.0 w / GLKit透明纹理