Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CCSprite *spriteWithColor (ccColor4F bgColor, float textureSize){
- //1: Create new CCRenderTexture
- rt = CCRenderTexture::renderTextureWithWidthAndHeight(textureSize,textureSize);
- // 2: Call CCRenderTexture:begin
- rt->beginWithClear(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
- // 3: Draw into the texture
- glDisable(GL_TEXTURE_2D);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- float gradientAlpha = 0.7;
- CGPoint vertices[4];
- ccColor4F colors[4];
- int nVertices = 0;
- vertices[nVertices] = CGPointMake(0, 0);
- nVertices = nVertices++; //now it's 1
- colors[nVertices] = (ccColor4F){0, 0, 0, 0 };
- vertices[nVertices] = CGPointMake(textureSize, 0);
- nVertices = nVertices++; //now it's 2
- colors[nVertices] = (ccColor4F){0, 0, 0, 0};
- vertices[nVertices] = CGPointMake(0, textureSize);
- nVertices = nVertices++; //now it's 3
- colors[nVertices] = (ccColor4F){0, 0, 0, gradientAlpha};
- vertices[nVertices] = CGPointMake(textureSize, textureSize);
- nVertices = nVertices++; //now it's 4
- colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};
- glVertexPointer(2, GL_FLOAT, 0, vertices);
- glColorPointer(4, GL_FLOAT, 0, colors);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
- CCSprite* noise = CCSprite::spriteWithFile("Noise.png");
- noise->setBlendFunc((ccBlendFunc){GL_DST_COLOR, GL_ZERO});
- noise->setPosition(ccp(textureSize/2, textureSize/2));
- noise->visit(); //recursive method that visit its children and draw them , part of node
- // 4: Call CCRenderTexture:end
- rt->end();
- // 5: Create a new Sprite from the texture
- return CCSprite::spriteWithTexture(rt.sprite.texture);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement