Hi Yuye,
Could you please help, following code is not working ,i am using cocos2dx 3.0 -> here is the code. I think problem is with opengl portion , may be i am doing it wrong …
RenderTexture* rt = RenderTexture::create(textureWidth, textureHeight);
rt->beginWithClear(color.r, color.g, color.b, color.a);
float gradientAlpha = 0.7f;
Point vertices[4];
Color4F colors[4];
int nVertices = 0;
vertices[nVertices] = Point(0, 0);
colors[nVertices++] = Color4F(0, 0, 0, 0);
vertices[nVertices] = Point(textureWidth, 0);
colors[nVertices++] = Color4F(0, 0, 0, 0);
vertices[nVertices] = Point(0, textureHeight);
colors[nVertices++] = Color4F(0, 0, 0, gradientAlpha);
vertices[nVertices] = Point(textureWidth, textureHeight);
colors[nVertices++] = Color4F(0, 0, 0, gradientAlpha);
// Set the shader program for OpenGL
setShaderProgram(ShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor));
CC_NODE_DRAW_SETUP();
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);
Sprite* noise = Sprite::create("Noise-hd.png");
BlendFunc blendFunc;
blendFunc.src = GL_DST_COLOR;
blendFunc.dst = GL_ZERO;
noise->setBlendFunc(blendFunc);
noise->setPosition(Point(textureWidth / 2, textureHeight/2));
noise->visit();
rt->end();
Sprite* sprite = Sprite::createWithTexture(rt->getSprite()->getTexture());
return sprite;