Run shader With Sprite, tell error 0x0502 when Sprite.cpp draw 591, I use cocos2d-x.2.4.1

Cocos2d: OpenGL error 0x0502 in /Users/chengxiaoer/Documents/MyHello/cocos2dx/proj.ios/…/sprite_nodes/CCSprite.cpp draw 591

//here is code

void CSEGrass::setupGlProgramm()
{
GLchar* pszFragSource =
#ifdef GL_ES precision mediump float; #endif uniform sampler2D u_texture; varying vec2 v_texCoord; varying vec4 v_fragmentColor; void main(void) { // Convert to greyscale using NTSC weightings float grey = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); gl_FragColor = vec4(grey, grey, grey, 1.0); }”;

GLchar* pszFragSource2 =
#ifdef GL_ES precision mediump float; #endif varying vec2 v_texCoord; uniform sampler2D u_texture; uniform float u_time; const float speed = 2.0; const float bendFactor = 0.2; void main(void) { float height = 1.0 - v_texCoord.y; float offset = pow(height, 2.5); // 4 multiply by sin since it gives us nice bending offset = bendFactor); vec3 normalColor = texture2D(u_texture, fract(vec2(v_texCoord.x + offset, v_texCoord.y))).rgb; float grey = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); gl_FragColor = vec4(normalColor, 1); }”;

m_pProgram = new CCGLProgram();
m_pProgram~~>initWithVertexShaderByteArray;
CHECK_GL_ERROR_DEBUG;
}
void CSEGrass::setupOneSprite
{
CCSprite* cloveSprite = CCSprite::create;
cloveSprite~~>setPosition(pt);
addChild(cloveSprite);
m_pArray~~>addObject;
cloveSprite~~>setAnchorPoint(ccp(0,0));

GLchar* pszFragSource =
#ifdef GL_ES precision mediump float; #endif uniform sampler2D u_texture; varying vec2 v_texCoord; varying vec4 v_fragmentColor; void main(void) { // Convert to greyscale using NTSC weightings float grey = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); gl_FragColor = vec4(grey, grey, grey, 1.0); }”;

GLchar* pszFragSource2 =
#ifdef GL_ES precision mediump float; #endif varying vec2 v_texCoord; uniform sampler2D u_texture; uniform float u_time; const float speed = 2.0; const float bendFactor = 0.2; void main(void) { float height = 1.0 - v_texCoord.y; float offset = pow(height, 2.5); // 4 multiply by sin since it gives us nice bending offset = bendFactor); vec3 normalColor = texture2D(u_texture, fract(vec2(v_texCoord.x + offset, v_texCoord.y))).rgb; float grey = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); gl_FragColor = vec4(normalColor, 1); }”;

//CCGLProgram pProgram = new CCGLProgram;
//pProgram~~>initWithVertexShaderByteArray;
//CHECK_GL_ERROR_DEBUG;
cloveSprite~~>setShaderProgram;
//pProgram~~>release;
cloveSprite~~>getShaderProgram~~>addAttribute;
cloveSprite~~>getShaderProgram~~>addAttribute;
CHECK_GL_ERROR_DEBUG;
cloveSprite~~>getShaderProgram~~>link;
CHECK_GL_ERROR_DEBUG;
cloveSprite~~>getShaderProgram->updateUniforms;
CHECK_GL_ERROR_DEBUG;
int var_timeUniformLocation = glGetUniformLocation~~>getProgram, “u_time”);
locations.push_back;
cloveSprite~~>getShaderProgram->use;
}
void CSEGrass::setupRowSprites
{
CCSprite
sp = CCSprite::create(“grass.png”);
CCPoint p1 = ccp(0, startPos.y);
CCPoint p2 = ccp(p1.x + sp->getContentSize().width, p1.y);
CCPoint p3 = ccp(p2.x + sp->getContentSize().width, p1.y);
CCPoint p4 = ccp(p3.x + sp->getContentSize().width, p1.y);
CCPoint p5 = ccp(p4.x + sp->getContentSize().width, p1.y);
CCPoint p6 = ccp(p5.x + sp->getContentSize().width, p1.y);
CCPoint p7 = ccp(p6.x + sp->getContentSize().width, p1.y);
CCPoint p8 = ccp(p7.x + sp->getContentSize().width, p1.y);
CCPoint p9 = ccp(p8.x + sp->getContentSize().width, p1.y);
CCPoint p10 = ccp(p9.x + sp->getContentSize().width, p1.y);

setupOneSprite(p1);
setupOneSprite(p2);
setupOneSprite(p3);
setupOneSprite(p4);
setupOneSprite(p5);
setupOneSprite(p6);
setupOneSprite(p7);
setupOneSprite(p8);
setupOneSprite(p9);
setupOneSprite(p10);
}


CSEGrass.cpp.zip (3.3 KB)

I’m not a pro with shaders, but i’d copy the sprite’s default shader (PositonTextureColor, I think) and make sure that one works.
If you code your shader incrementally, step by step, it will be easier for you to find the error.

I’d also make the tests with only one sprite, at the center of the screen, avoiding code like setupRowSprites().

If you could simplify your example and use code highlighting (see my signature below) it would be easier to get help.
Good luck!