“The original state of a window is black. The scene is already transparent.”
I can confirm that this statement IS NOT CORRECT. The original state of the window is not always black and is an incorrect assumption, one that comes back to bite anyone trying to do an augmented reality app.
If you, for instance, place a transparent EAGLView onto a UIImagePickerController view (camera stream) and place a scene with a transparent layer onto that, you do NOT get a fully transparent layer/scene as you would expect…you get a black box i the middle of your camera view.
It seems that the alpha channel calculations on the layer take into account the color and alpha of the underlying scene…so if you accept the underlying scene’s original black color, and say, put a white layer over top, and try to turn down the white layer’s alpha it will go from white opaque, to grey translucent, back to black opaque (as the white layer become transparent exposing fully the black opaque scene). Interestingly, the underlying black opaque scene is influenced by the layer above it, that is, it does become translucent (and expose the underlying camera view) at points as you turn down the alpha of the white layer overtop of it…but as the alpha of the white layer becomes negligible in the calculations as it trends to zero the black scene goes back to being opaque and instead of a see through augmented reality app you get an ugly black scene box…to test this, simply make your CCEAGLView slightly smaller than the window and make it a child of a camera overlay view…you can watch it go translucent then back to opaque because of that underlying assumption that the default underlying UIView will always be black.
So, the answer…in Cocos2dx v3.1.1, if you wish for a fully transparent scene/ColorLayer as is needed for augmented reality apps (or indeed any cocos2d-x app that wishes to be transparent overtop of native views…video players etc), you need to ensure that your scene and your layer are the SAME COLOR…i use a white LayerColor (with alpha 0) and a white scene.
I have confirmed this behaviour only for iOS so far…will write more when I get to Android/Windows in my app dev cycle if I remember.