03 January, 2010

Create a OpenGL ES project without using Interface Builder

In this section I will explain you how to create a OpenGL ES project without using Interface Builder.


Step 1 : First create a OpenGL ES project from template available in Xcode.
Step 2 : Delete nib dependency in project:
  1. Delete nib file from Resources.
  2. Delete "main nib" key entry in info.plist.
Step 3 : Update the main method which is in main.m as follows:
we have to change 4th parameter of UIApplicationMain method call to @"ProjectNameAppDelegate" from nil.
Step 4 : In appDelegate method we need to create window, view manually, earlier Interface builder use to do this for us.In header file we need to remove IBOutlet from window, glView declaration(as we are not using Interface Builder).
Now we need to update applicationDidFinishLaunching to create window, glView manually:
  1. Create the window.
  2. Create EAGLView.
  3. Add the EAGLView to window.
  4. make window visible.
//Create the window.
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
//Create EAGLView.
glView = [[EAGLView alloc] initWithFrame:window.bounds];
//Add the EAGLView to window.
[Window addSubview:glView];
//make window visible.
[window makeKeyAndVisible];


Step 5: Now we need to replace following code in EAGLView.m:
- (id)initWithCoder:(NSCoder*)coder {
    if ((self = [super initWithCoder:coder])) {
with


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {

following is the video that illustrates this tutorial:




No comments:

Post a Comment