我尝试淡化预乘纹理,使其逐渐变得透明。我遇到的问题是当alpha值从1变为0时,纹理会变为黑色而不是透明。
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// premultiply color
color.r = r * alpha;
color.g = g * alpha;
color.b = b * alpha;
color.a = alpha;
看图像(上传图像需要至少10的声誉)
https://sites.google.com/site/soundsculptorpro/_/rsrc/1442889599502/games/blend.png
添加剂混合正确淡出,但它太亮了。
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
// premultiply color...
任何想法为什么添加剂混合会正确淡化,但alpha混合会淡化为黑色?
的更新
片段着色器(cocos2d 2.1)...
" \n\
#ifdef GL_ES \n\
precision lowp float; \n\
#endif \n\
\n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
uniform sampler2D CC_Texture0; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord); \n\
} \n\
";
顶点着色器(cocos2d 2.1)...
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
attribute vec4 a_color; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = CC_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
v_texCoord = a_texCoord; \n\
} \n\
";
_ccV3F_C4F_T2F vertices[4];
glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(_ccV3F_C4F_T2F), &vertices[0].vertices);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, sizeof(_ccV3F_C4F_T2F), &vertices[0].colors);
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(_ccV3F_C4F_T2F), &vertices[0].texCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
答案 0 :(得分:0)
感谢Columbo,这是color.a!实用程序函数中存在一个始终将color.a设置为1的错误。