Shaders and home button

Hi,

I’m developing a game which uses some basic shaders (grayscale i.e.). It works as a charm in iOS (in fact the app has been already sent to App Store reviewers), but in Android we have faced a problem than cannot solve:

Everything goes well except if the user pushes the Home Button and later enters again to the app; the shaders doesn’t work well in this situation. I’ve tried to find info about this problem, but the only thing I’ve seen is this thread: http://www.cocos2d-x.org/boards/6/topics/6197

Here Danil Valmar says that the solution is to reload Shaders:

Hi,
joseph pinkasfeld and Le Yang can you post full solution for cocos2dx v2.0.3? Current problem also cause shader programs. It is easy to reload shaders, but for me redrawing all rendertextures is not that simply.

But I don’t know how to do this. I’ve tried everything and the app always crashes with the message “Failed to compile shaders” if I try to reload my custom shaders on “applicationWillEnterForeground”.

Can anyone help me please??

Thanks in advance!

No one has faced this problem?

Hi, Danil’s advice is correct. You should reload your shaders when the app returns to the foreground.

The easiest way to achieve this is to listen for the foreground event.

Try using this:

CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
                                                                  callfuncO_selector(SelectorMethodName),
                                                                  EVNET_COME_TO_FOREGROUND,
                                                                  NULL);

Reload your shader in the callfunc selector method.

Good luck!

refer to cocos2d-x samples/Cpp/TestCPP/Classes/ShaderTest

Thanks for your answers! Today I’ll give a look!

Well, thanks both of you for your indications! You have helped a lot!
Now I see I am a little stupid for not remembering to look at the sample codes :-DD