Advertisement
Guest User

Untitled

a guest
Jul 28th, 2011
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. CCSprite *spriteWithColor (ccColor4F bgColor, float textureSize){
  2. //1: Create new CCRenderTexture
  3. rt = CCRenderTexture::renderTextureWithWidthAndHeight(textureSize,textureSize);
  4. // 2: Call CCRenderTexture:begin
  5. rt->beginWithClear(bgColor.r, bgColor.g, bgColor.b, bgColor.a);
  6. // 3: Draw into the texture
  7. glDisable(GL_TEXTURE_2D);
  8. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  9.  
  10. float gradientAlpha = 0.7;
  11. CGPoint vertices[4];
  12. ccColor4F colors[4];
  13. int nVertices = 0;
  14.  
  15. vertices[nVertices] = CGPointMake(0, 0);
  16. nVertices = nVertices++; //now it's 1
  17. colors[nVertices] = (ccColor4F){0, 0, 0, 0 };
  18. vertices[nVertices] = CGPointMake(textureSize, 0);
  19. nVertices = nVertices++; //now it's 2
  20. colors[nVertices] = (ccColor4F){0, 0, 0, 0};
  21. vertices[nVertices] = CGPointMake(0, textureSize);
  22. nVertices = nVertices++; //now it's 3
  23. colors[nVertices] = (ccColor4F){0, 0, 0, gradientAlpha};
  24. vertices[nVertices] = CGPointMake(textureSize, textureSize);
  25. nVertices = nVertices++; //now it's 4
  26. colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};
  27.  
  28. glVertexPointer(2, GL_FLOAT, 0, vertices);
  29. glColorPointer(4, GL_FLOAT, 0, colors);
  30. glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);
  31.  
  32. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  33. glEnable(GL_TEXTURE_2D);
  34.  
  35. CCSprite* noise = CCSprite::spriteWithFile("Noise.png");
  36. noise->setBlendFunc((ccBlendFunc){GL_DST_COLOR, GL_ZERO});
  37. noise->setPosition(ccp(textureSize/2, textureSize/2));
  38. noise->visit(); //recursive method that visit its children and draw them , part of node
  39.  
  40. // 4: Call CCRenderTexture:end
  41. rt->end();
  42.  
  43. // 5: Create a new Sprite from the texture
  44. return CCSprite::spriteWithTexture(rt.sprite.texture);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement