The CCGL wrapper eases the use of Cinder within a typical Cocoa project for Mac OSX. Thus allowing C++/Obj-C creative coders to build Mac apps bearing several Cinder sketches within the same app, as well as Cocoa sliders, buttons... as further introduced in this article.

Its XCode templates provide the best starting points for yummy "Coco acid flavored" applications.

▸ Launching your first example project

Download the CCGL examples package. Unzip the file and place the "CCGL" folder you obtain at the root of your Cinder folder, besides "samples", "blocks", "lib"...

Within the CCGLBasic project folder, open CCGLBasic.xcodeproj and run it: the project should build and the CCGLBasic Window should appear with a colorful, rotating cube whose size you can adjust with a Cocoa slider such as illustrated here under.


▸ Installing & using the templates

First navigate to within the Applications folder on your Mac, right-click on it and select 'Show Package Contents' from the context menu. Then take a deep breath, and place the templates' *.xctemplate that you've previously downloaded folders there:
/Contents/Developer/Library/Xcode/Templates/Project Templates/Mac/Application

Phew. You're ready. Launch XCode, create a new project and select the template of your choice from the MacOSX > Application menu. Make sure to save the project's folder inside of a folder (ie. "MyCCGLTouchProjects") at the root of your Cinder folder.

▸ A brief note about the files and their roles

Unfold all the groups in the project's hierarchy in order to get something similar to the image on the left.

In order to use the Cinder framework within a typical XCode project, it is necessary to go around the application building process that magically happens when rendering a Cinder project. In other words, replace the AppBasic class, from which all Cinder MacOS projects inherit (ie. class MyGreatApp : public AppBasic ...), with a combination of an OpenGL capable view that is added through Interface Builder and that is bound to a class inheriting Cinder capabilities.

The OpenGL capable view that is used here is unfortunately NOT an NSOpenGLView as the name would clearly suggest. Instead, it's an NSCustomView, and you'll find it in the MainMenu.nib file (that's in the "Assets" group) displaying the name of the class that's telling it what to do.

Indeed, this NSCustomView is bound to the MyCinderGLDrawing class, whose .h and .mm files are placed in the "MyClasses" group (Why .mm ? Because it's an Objective-C++ file, that welcomes Obj-C syntax as well as C++ syntax. More on this in the next paragraph.).

The MyCinderGLDrawing class may bear any name you like. That is where you're going to write what's being drawn in the NSCustomView. But it must inherit from the CCGLView class whose .h and .mm you will find under the "CCGLCore" group. Everything in that CCGLCore group should remain intact unless you want to implement new functions, or tweak the defaults... at your convenience.

Finally the MyController class, whose .h and .mm you will find in the MyClasses group, is the place where all the Interface Builder buttons, sliders, etc. that you've added in the MainMenu.nib are being connected to the CCGLView(s) that you're willing to control with them. For clarity, in all the examples provided in the CCGL package, MyController inherits from NSObject (and displays as a blue cube in Interface Builder, where you get to connect IBOutlets and IBActions). It happens sometimes that you'll be better off extending NSWindow. That's obviously possible. Also, as with MyCinderGLDrawingMyController may bear any name you like. And you may use as many controllers as you care to.

▸ What examples are there?

Apart from the CCGLBasic example described up there, 10 other projects are available in the package:

  • CCGLBlobDetector is the most complete example application, and it's interesting to check out for its OpenCV block integration.
  • CCGLDragnDropFiles features the Cocoa brew of the file drag and drop functionality.
  • CCGLFullScreen example shows off how to maximize a Cinder drawing to full screen Cocoa-style, and escape it via -(void) keyDown:(NSEvent *)evt; .
  • CCGLLights lets you play with specularity via an NSSlider.
  • CCGLMesh2VBO example transforms mesh data into a VBO and plays with it.
  • CCGLMultipleDrawings is a very basic example of how to use 2 independent Cinder sketches within the same NSWindow.
  • CCGLOBJ2Mesh makes sure that importing an .OBJ 3d file, translating its data to mesh and throwing shader light on it still works.
  • CCGLOSCBlock does what its name says it does, and comes with a Processing sketch to test the OpenSoundControl connection both ways.
  • CCGLParticles shows how to use a ParticleController class and a Particle class in much the same way as explained in Robert Hodgin's "Hello, Cinder" tutorial.
  • CCGLPicking3D is a port of Paul Houx's great Picking 3D sample as distributed in the Cinder package. A nice place to check out how textures and GLSL shaders work too.

▸ Change log: latest additions & updated features

CCGL was last updated on 08/18/2015 with:

  • 64-bit architecture: fully tested and supported
  • Cinder 0.8.6: support for the latest stable release