-->

Cocos2d - apply GLImageProcessing effect to CCSpri

2020-07-27 03:33发布

问题:

Apple's oplengl GLImageProcessing loads an image and applies image adjustments: brightness, saturation, contrast, hue and sharpness.

How can GLImageProcessing be used on a CCSprite?

Any help would be appreciated!


Update: Cocos2d v2 has shader support. For Image Effects look up GLSL shader called Photoshop Math.


回答1:

I've applied approach from GLImageProcessing to change the hue of CCSpite and wrote a subclass of CCSprite for convenient usage. Check this out: https://github.com/alex314/CCSpriteWithHue



回答2:

Cocos2D is an Objective-C framework wrapping openGL plain C API. GLImageProcessing Sample code is an example of using openGL.

To apply similar effects to a CCSprite, AFAIK, there is not hue, brightness or such image processing effects into Cocos2D. So I would suggest to override CCSprite and code your own drawing, inspiring from GLImageProcessing.

The interesting entry points are, for CCSprite :

-(void) draw

Which is responsible of openGL drawing of you sprite.

For GLImageProcessing :

 void drawGL(int wide, int high, float val, int mode)


回答3:

There are several discussions to implement like GLImageProcessing with cocos2d. You can call any GL API in cocos2d.

  • texture modulation
  • Using a texture combiner to render CCSprite in greyscale?
  • Gaussian BLUR implemented in cocos2d!