在Sprite 多个变量 m_bGray 并构造初始化为false
在多个函数直接上代码。官方什么东西都吭,我带你们飞(终于可以装B了,研究了4五天)
void Sprite::setGray(bool bGray)
{
if (m_bGray == bGray)
return;
m_bGray = bGray;
if (bGray)
{
GLchar* pszFragSource =
"#ifdef GL_ES \n \
precision mediump float; \n \
#endif \n \
uniform sampler2D u_texture; \n \
varying vec2 v_texCoord; \n \
varying vec4 v_fragmentColor; \n \
void main(void) \n \
{ \n \
// Convert to greyscale using NTSC weightings \n \
vec4 col = texture2D(u_texture, v_texCoord); \n \
float grey = dot(col.rgb, vec3(0.299, 0.587, 0.114)); \n \
gl_FragColor = vec4(grey, grey, grey, col.a); \n \
}";
CCGLProgram* pProgram = new CCGLProgram();
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_noMVP_vert, pszFragSource);
this->setShaderProgram(pProgram);
pProgram->release();
CHECK_GL_ERROR_DEBUG();
pProgram = this->getShaderProgram();
pProgram->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
pProgram->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
pProgram->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
CHECK_GL_ERROR_DEBUG();
pProgram->link();
CHECK_GL_ERROR_DEBUG();
pProgram->updateUniforms();
CHECK_GL_ERROR_DEBUG();
}
else
{
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
}
}







福利拿走吧!


