Skip to content

Instantly share code, notes, and snippets.

@butihuzi
Last active December 23, 2015 17:09
Show Gist options
  • Save butihuzi/6667106 to your computer and use it in GitHub Desktop.
Save butihuzi/6667106 to your computer and use it in GitHub Desktop.
cocos2d-x cancel render to texture with OpenGL CCGLProgram. cocos2d-x 取消中给 ccSprite 添加的滤镜效果。
void CommUtil::enableSprite(CCSprite* sp)
{
const 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 \
gl_FragColor = vec4(col.r, col.g, col.b, col.a); \n \
}";
CCGLProgram* pProgram = new CCGLProgram();
pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, pszFragSource);
sp->setShaderProgram(pProgram);
pProgram->release();
sp->getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
sp->getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
sp->getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
sp->getShaderProgram()->link();
sp->getShaderProgram()->updateUniforms();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment