Skip to content
Diego Gomez Deck edited this page May 27, 2015 · 6 revisions

Create a new iOS application in Xcode:

  • File > New > Project...
  • Set these options trough the wizard steps:
  • Template: iOS > Application > Single View Application
  • Give a name to your application
  • Locate the folder to save your project

G3M Settings

Once you created your project some configuration is required.

General

General Settings section

  • Set the Deployment Target 6.1 within the General Section of the setting screen.
  • Link the g3m framework: scroll down to the Linked Frameworks and Libraries item and click on + button. Click on Add Other... button to locate your local copy of g3m framework. Open it and wait for indexing files. g3m framework location
  • Link the g3m static library: once the framework is indexed, click on the same + button again to add the library. The popup window shows you the g3m library now on your Workspace. Select it and click on Add button. adding g3m library
  • Link the other required frameworks and libraries the same way you did with g3m library:
  • CoreData.framework
  • OpenGLES.framework
  • QuartzCore.framework
  • CFNetwork.framework
  • Security.framework
  • libsqlite3.dylib
  • libicucore.dylib

At the end, your Linked Frameworks and Libraries section will look this: linked frameworks and libraries

Build Settings

Go to the Build Settings section and use the searcher to easily find and set the following options:

  • C++ Language Dialect: Compiler Default
  • C++ Standard Library: Compiler Default
  • Preprocessor Macros:
  • Debug: C_CODE DEBUG=1
  • Release: C_CODE
  • Other Linker Flags: -ObjC

Starting with the app

The Layout: iPhone storyboard

  • Click on the Main_iPhone.storyboard on the Project Navigator Panel to open it.
  • Now click on the view to get it selected and show the Identity inspector (third button on the right panel).
  • Set G3MWidget_iOS as the custom class of your view view custom class
  • Show the Assistant editor (second button on the right toolbar) and you will get a split screen showing the storyboard on the left and the ViewController header file on the right.
  • Ctrl + click on the view and drag and drop on the view controller view, after @interface HWViewController : UIViewController and before @end lines to create a reference of your view in your code (IBOutlet). Give a name for the reference on the balloon. Once you click connect you will get this code on your view controller: @property (strong, nonatomic) IBOutlet G3MWidget_iOS *g3mWidget; adding reference naming the reference Tip: Add a class reference to fix the error. Add @class G3MWidget_iOS; after #import <UIKit/UIKit.h> line.

The Layout: iPad storyboard

  • Repeat the same process for the Main_iPad.storyboard.
  • This time when referencing the view, drag and drop over the existing property instead of adding a new one. Linking existing reference

You may have a g3m widget on any view you want but for this example we select the main view to get a full screen g3m widget.

The g3m Code

  • The first step is renaming the view controller. g3m uses C++ code thus your view controller should have .mm extension to get it working. Rename YourPrefixViewController.m to YourPrefixViewController.mm and save.
  • Go to the viewDidLoad method and add this lines after the comment: G3MBuilder_iOS builder([self g3mWidget]); builder.initializeWidget();
  • You will have to import some classes:
#import <G3MiOSSDK/G3MWidget_iOS.h>
#import <G3MiOSSDK/G3MBuilder_iOS.hpp>
  • Add some new methods to get the widget working:
// Start animation when view has appeared
- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  // Start the glob3 render loop
  [self.g3mWidget startAnimation];
}
// Stop the animation when view has disappeared
- (void)viewDidDisappear:(BOOL)animated
{
  // Stop the glob3 render loop
  [self.g3mWidget stopAnimation];
  [super viewDidDisappear:animated];
}
// Release property
- (void)viewDidUnload
{
  self.g3mWidget        = nil;
}
  • Save all the files. Clean and build the project.
  • Run the app either on your iOS device or the iOS Simulator and say Hello to your g3m world!

Hello World running

Project code

You can find the full Hello World project here