我试图在Cocos2dx 2,OpenGL ES2中为纹理添加渐变。 但是OpenGL内容没有得到渲染。Cocos2dx CCRenderTexture - OpenGL ES2未呈现
这个代码是基于教程链接: http://www.raywenderlich.com/3857/how-to-create-dynamic-textures-with-ccrendertexture
CCRenderTexture *rt = CCRenderTexture::create((int)textureSize, (int)textureSize);
rt->beginWithClear(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
float gradientAlpha = 0.5;
CCPoint vertices[4];
ccColor4F colors[4];
int nVertices = 0;
vertices[nVertices] = CCPointMake(0, 0);
colors[nVertices++] = ccc4f(0, 0, 0, 0);
vertices[nVertices] = CCPointMake(textureSize, 0);
colors[nVertices++] = ccc4f(0, 0, 0, 0);
vertices[nVertices] = CCPointMake(0, textureSize);
colors[nVertices++] = ccc4f(0, 0, 0, gradientAlpha);
vertices[nVertices] = CCPointMake(textureSize, textureSize);
colors[nVertices++] = ccc4f(0, 0, 0, gradientAlpha);
// Set the shader program for OpenGL
setShaderProgram(CCShaderCache::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);
ccGLBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);
CCSprite* noise = CCSprite::create("Noise.png");
ccBlendFunc blendFunc;
blendFunc.src = GL_DST_COLOR;
blendFunc.dst = GL_ZERO;
noise->setBlendFunc(blendFunc);
noise->setPosition(ccp(textureSize/2, textureSize/2));
noise->visit();
rt->end();
return CCSprite::createWithTexture(rt->getSprite()->getTexture());
请让我知道如果我做错了什么。谢谢。
谢谢!请问您最终如何找出解决方案? –