-
CocoaCinderGL Touch wrapper
first release: 09/26/2011 | latest update: 11/20/2011
This wrapper eases the use of Cinder in a typical XCode project. Thus allowing C++/Obj-C creative coders to build iOS (iPhone, iPad) apps showing several "Cinder sketches" in tabs or SplitView configurations, and using UISlider's, UISwitch's, etc. to control them.
If you're looking for the Mac OSX version of this: CocoaCinderGL wrapper.Launching an example project
Download the CCGLTouch examples package. Unzip the file and place the "CCGLTouch" you obtain inside of your Cinder folder, at the same level as the "samples", "blocks", "lib"... Open CCGLTouchBasic.xcodeproj and run it in the iPhone Simulator: the project should build and the CCGLTouchBasic app should launch. A colorful cube should rotate and look somewhat similar to the third iPhone sim pic above.
If the project build failed, then the linking is probably not right. That's probably because the CCGLTouch folder you've just unzipped & renamed is not placed at the root of your Cinder folder. If you keep experiencing problems with linking, check the User-defined build settings of the project and change the CINDER_PATH value until it all connects properly. Please report any other issue in the comments section below!
Using the templates
These XCode templates provide starting points for "CCGLTouch flavored" applications. The basic template features a colored cube and a UISlider to control the size of the cube. Download them here. You may also find them on a separate GitHub repository.
To install the templates, place their *.xctemplate folders inside of /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application, besides "Cocoa Touch Application.xctemplate", "Cocoa Touch Familied Application.xctemplate", etc.
Then launch XCode, create a new project and select the template of your choice from the iOS > Application menu displayed in the dialog box.
Make sure to save the project inside of a folder placed at the root of your Cinder folder, besides the "samples", "lib", "boost" folders. Typically a folder named "CCGLTouch" where all the examples sit... If you decide to do otherwise, you'll have to change the User-Defined CINDER_PATH setting of the project's target to comply with the relative location of the project you've just created.
First, unfold all the groups in the project's hierarchy in order to get something similar to the image on the left.A brief note about which files are there, why they're there, and what you can do with them
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. This is what MyAppDelegate and the ViewController(s) are here for. The AppDelegate generates a view that is of MyCinderGLDrawing class type, and is controlled by the MyViewController.
The MyCinderGLDrawing class may bear any name you like. That is where you're going to write what's being drawn in the view. But it must inherit from the CCGLTouchView class whose .h and .mm you will find under the "CCGLTouchCore" group. Everything in that CCGLTouchCore group should remain intact unless you want to implement new functions, or tweak the defaults... at your convenience.
Finally the MyViewController 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 MyViewController.xib are being connected to the MyCinderGLView that you're controlling with them. Obviously, when using several CCGLTouchView's in the same project, all of these assets (MyCinderGLView.h, MyViewController.h, MyViewController.xib) are multiplied by as many views as you'll want to use. For a simple example, check out the "CCGLTouchTabs" sample included in the package.
What are the main differences with the CCGL wrapper for OSX ?
To be honest, the "Touch" version of the wrapper is slightly more complicated to use. This is due to the specificity of iOS' Cocoa, that requires programmers to follow the rules of MVC more closely. In a way, that's a good thing. Eventhough it is very enjoyable to be able to not follow the rules from time to time ;).
Therefore you're going to have to use an AppDelegate that inherits from CCGLAppDelegate, and pass the CCGLTouchView instances created there to the corresponding CCGLViewController instance. Look for the following method in the controller:
- (void)setGLView:(MyCinderGLView *)view
{
glView = view;
}Also, to clear up the AppDelegate's code from most of the verbose Cocoa stuff that comes with the initialization, I've created a convenience method -(void)launch in the AppDelegate that's called from the native -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions.
On the plus side, because that's one of the coolest features of Apple's mobile devices, accelerometer data is available in CCGLTouch, Cinder-style (void accelerated() has been translated). But be aware that events are being picked up in the AppDelegate, since they clearly target the device as a whole rather than being specific to any view. Thus allowing you, the creative coder, to creatively use acceleration accross all instances of CCGLTouchView you fancy to use!
Finally, the multi-touch capability of Cinder's iOS framework is also available. I never found myself needing to code it for the OSX wrapper, but here, it's an absolute must-have. An example is available in the package.
What examples are there ?
Apart from the CCGLTouchBasic example described up there, 5 other projects are available in the package:
- CCGLTouchMayaCam is equivalent to CCGLTouchBasic, except for its single-touch controlled camera.

- CCGLTouchTabs features 2 independent CCGLTouchView's, each being shipped with their own UISlider.


- For CCGLTouchAccelerometer, you'll have to connect a device, either iPhone or iPad, if you want to be able to test the accelerometer functionnality. This example relates heavily on the iPhoneAccelerometer sample that ships with Cinder.

- CCGLTouchMultitouch is a CocoaTouch-revamped edition of Cinder's MultiTouchBasic. It features a UISwitch that lets the user turn on/off the yellow circle located under the fingers.

- CCGLTouchSplitView is an iPad specific example, that illustrates of the SplitView on that platform, bearing a UITableView as the "root view", that has influence over the "detail view" (in our case, the place where Cinder does its magic).

- CCGLTouchMayaCam is equivalent to CCGLTouchBasic, except for its single-touch controlled camera.
About
Hello, I'm Matthieu Savary,
user experience & interaction designer at USER STUDIO, France's first service design company that I've co-founded with Matthew and Denis.
As a part time creative coding junky, one of my favorite hobbies involves building "authoring tools" for New Media Art. read more »
Random works
-
Cimes
lab | 2008
-
User Comments Mod...
studio | 2010
Contact
→ Via LinkedIn→ Via email : contact@smallab.org












« @Llams : you're guessing right, your question is very much Cinder related ;) I haven't tried VBO's on iOS yet, but from looking at the source, and from reading what this guy is asking about on the forum http://forum.libcinder.org/#topic/23286000000700019 it seems they're not available, or at least not in the same way as they are on the desktop with void draw(const VboMesh &vbo); . »
Matthieu Savary
« I've played with the examples and things look great so far. One question, which I guess has more to do with Cinder itself and the CCGLTouch wrapper: Is it possible to use VBO's? I get a compiler error. Thanks. »
Llams