Created
September 23, 2013 09:43
-
-
Save butihuzi/6668405 to your computer and use it in GitHub Desktop.
cocos2d-x render to texture with OpenGL CCGLProgram.
cocos2d-x 中给 ccSprite 添加灰白滤镜(类似黑白照片效果)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CommUtil::disableSprite(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 \ | |
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_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
注释下,取消的代码在 https://gist.github.com/butihuzi/6667106