I found the following changes were needed to get the transparency effect I was looking for:
First, the blue gradient seen in the OP was in the app's -[BaseMenu startupActions].
CCNodeGradient *ng = [CCNodeGradient nodeWithColor:CCColorRefFromCCC4F(kCCC4FBlue) fadingTo:[CCColor colorWithRed:0.2 green:0.2 blue:0.1]];
With that mystery solved, I worked through the OpenGL rendering to find everything that modified the context, trying to find their origins, and make the smallest amount of changes to achieve the desired result.
The only upgrades needed to the frameworks were subclasses for 2 Cocos2d classes and 1 Cocoa class. I added CCClearGLView, a CCGLView subclass to add changes needed for the OpenGL context to support transparency.
@interface CCClearGLView : CCGLView
- (void) prepareOpenGL
GLint aValue = 0;
[[self openGLContext] setValues: &aValue
I also added CCClearView, an NSView subclass to replace the NSView instance which is the default contentView in the app window.
@interface CCClearView : NSView
And finally, I added CCClearWindow, a CCWindow subclass, to replace either it or NSWIndow for programmatic or nib-based instantiations.
@interface CCClearWindow ()
- (id)initWithFrame:(NSRect)aFrame fullscreen:(BOOL)aFullscreenFlag
self = [super initWithFrame: aFrame fullscreen: aFullscreenFlag];
if(self != nil)
[self setOpaque: NO];
[self setBackgroundColor: [NSColor colorWithDeviceRed: 0 green: 0 blue: 0 alpha: 0]];
You can then simply create a nib that contains all three classes like so:
Where the view hierarchy is CCClearWindow > CCClearView > CCClearGLView.
A few notes on transparency on macOS: CCClearWindow's parent class has shadows disabled by default. If you override this, be aware that switching apps will leave an odd artifact in the window. Along with the title bar's shadow, you can see the odd white triangles along with their shadows in this pic:
Minor App Additions
Now that the framework has been extended to allow us to have transparent windows, a couple changes remain for scenes to actually make their backgrounds transparent. Here are the details.
For the simplest of apps, such as the one I started with here, I wanted the models to retain their normal opacity. I just wanted them to appear floating above the content of everything under them.
There are two places where settings for achieving that transparency must be changed, due to Cocos3d's architecture.
Changing the CCScenery
First, because Cocos3d is built on top of Cocos2d, we must make Cocos2d give us the transparency we want. Cocos2d's CCScene defines property color for the scene's background color. Let's make it transparent.
Add this to the -startUpAction method of every CCScene subclass which needs to be transparent:
_color = kCCC4FBlackTransparent;
Next, for each CC3Scene subclass with a transparent background, use either one of the following in -initializeScene:
If you also have models with some transparent components,
self.opacity = 0; // Or the correct value for your scene.
Or if as described in the CC3HelloWorld comments for this method, the scene is empty because you have a POD which has opacity turned off, use this:
self.opacity = kCCOpacityFull;
self.backdrop.opacity = 0; // Or the correct value for your scene.
And everything should work fine.
That's All, Folks!
Next up: adding support to Cocos3d for the Leap Motion.