Last active
December 23, 2015 17:09
-
-
Save butihuzi/6667106 to your computer and use it in GitHub Desktop.
cocos2d-x cancel 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::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