Installing OGRE XCode template for iOS

This is the continuation of my previous blog Building OGRE for iOS. To install the template, you need to follow these steps.

OGRE XCode template

This will install the OGRE template for you. Let us create our first sample OGRE demo using the template we installed it now. To do that, open XCode and select the OGRE template and hit next.

OGRE XCode template

If you see the next attached screenshot carefully, for some reason, the XCode was not letting me add ‘/’ at the beginning of the root SDK path of OGRE. Just ignore it for now. Lets correct this later by making few changes in the XCode project settings.XCode project creation

Now, select the target ‘DemoApp’. Now, select ‘Header Search Paths’ under ‘Build Settings’ and add the missing ‘/’ . Also, make the same changes for ‘Library Search Paths’ too 🙂

OGRE demo app project settings

Now. it’s time to compile the app. If you have done everything right then you should see this error 🙂

 

Undefined symbols for architecture i386:
"boost::system::system_category()", referenced from:
__GLOBAL__I_a in main.o
__GLOBAL__I_a in OgreDemoApp.o
__GLOBAL__I_a in OgreFramework.o
boost::unique_lock<boost::recursive_mutex>::lock() in libOgreMainStatic.a(OgreConfigFile.o)
boost::recursive_mutex::recursive_mutex() in libOgreMainStatic.a(OgreConfigFile.o)
__GLOBAL__I_a in libOgreMainStatic.a(OgreConfigFile.o)
__GLOBAL__I_a in libRenderSystem_GLESStatic.a(OgreGLESPlugin.o)
...
"boost::system::generic_category()", referenced from:
__GLOBAL__I_a in main.o
__GLOBAL__I_a in OgreDemoApp.o
__GLOBAL__I_a in OgreFramework.o
__GLOBAL__I_a in libOgreMainStatic.a(OgreConfigFile.o)
__GLOBAL__I_a in libRenderSystem_GLESStatic.a(OgreGLESPlugin.o)
__GLOBAL__I_a in libOgreMainStatic.a(OgreLogManager.o)
__GLOBAL__I_a in libOgreMainStatic.a(OgreQuaternion.o)
...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To fix this error, add -lboost_system in the Other Linker Flags. That’s it…Compile and Run the program now. You should see the OGRE beast staring at you 🙂

OGRE Simulator beast

Compiling OpenCV source to support iOS 5.0

The latest version of the OpenCV framework isn’t compatible with anything other than iOS 6.0. This is due to the script what they used to build the framework. Since they have not specified the deployment target, the XCode takes iOS 6.0 (the latest SDK) as the default deployment target. This is very annoying as there are many users who still use iOS 5.0.

The latest OpenCV framework[v2.4.5] for iOS can be downloaded from here. If you try to build the application using this framework and try to run the compiled app on iOS 5, you will encounter this error.
 

dyld: lazy symbol binding failed: Symbol not found: _objc_setProperty_nonatomic
Referenced from: /var/mobile/Applications/9C52EB2F-9A11-4656-BBAC-0EE6960A323B/insite.app/insite
Expected in: /usr/lib/libobjc.A.dylib
dyld: Symbol not found: _objc_setProperty_nonatomic
Referenced from: /var/mobile/Applications/9C52EB2F-9A11-4656-BBAC-0EE6960A323B/insite.app/insite
Expected in: /usr/lib/libobjc.A.dylib

After googling, I ended up with this link where they have addressed the problem as well as the fix for the problem. I had to download the entire OpenCV source from github.Though this wasn’t the latest code [v2.4.3], I still downloaded the source as this had deployment target correction script.

After you download the source, you need to execute the following 2 commands in the terminal.

cd /Users/praveencastelino/Downloads/opencv-ios_deployment_target_722dedb/ios
python ./build_framework.py /Users/praveencastelino/Downloads/ 5.0


1] go to the iOS folder in the OpenCV source.
2] Excecute the python script python ./build_framework.py <build directory> <deployment target>

If everything works fine then you should have the OpenCV framework compiled to run on iOS 5.0.
OpenCV build folder structure

You can also download the OpenCV framework that I have compiled from here.

Building OGRE for iOS

I was looking out for a 3D Engine (OpenSource) to render 3D models. I wanted to use Cocos3d but this has few limitations. It is not a cross platform engine. [ I can’t ignore my friend Android 😦 ]. Also, it lacks many of the cool features when compared to sophisticated 3D engines. The next engine was OGRE. This is written C++ and a cross platform engine. Moreover, this is exactly what I was looking for. After downloading the source, the next big task was to compile the source. There are many tutorials available in the website but most them are obsolete. So I thought of writing one myself to help someone to quickly get started with OGRE 🙂

Follow the following steps to compile OGRE on iOS platform:

  • Get the latest source from here(v1.8.1)
  • Download the OGRE iOS dependancy and XCode template from here(1.8)
  • Open the iOS dependancies dmg and copy the folder iOSDependencies to the source folder ogre_src_v1-8-1. Ensure that the iOSDependencies and OgreMain folder are at the same hierarchical level.
  • OGRE folder structure
  • Now, navigate to the SDK -> iOS folder. You should find a make_ios.sh script.iOS script
  • Open the terminal and navigate it to the above folder where the script resides and run the script ./make_ios.sh in the terminal.
  • If everything worked fine then you should see a build folder in the same location where the script was. This folder contains a XCode project. XCode Build folder
  • Launch the  XCode project and set the target to SampleBrowser. Run the project. Wait for the Simulator to launch the OGRE beast 🙂XCode OGRE Project

PS: XCode Version 4.6.1 (4H512) and OS X (10.8.3)

iOS Resolution

Useful info about iOS devices:

iPhone Resolution
iPhone 3GS 480-by-320-pixel resolution at 163 ppi
iPhone 4S 960-by-640-pixel resolution at 326 ppi
iPhone 5 1136-by-640-pixel resolution at 326 ppi
iPad 4 2048-by-1536 resolution at 264 ppi
iPad mini 1024-by-768 resolution at 163 ppi
iPad 2 1024-by-768 resolution at 132 pip

Cool utility method to display HH:MM:SS from seconds

When I was developing video recording application, I had to display the time in HH:MM:SS format.
I wrote a utility method which does the same. It takes seconds as input and returns a NSString. Hope this helps iOS community 🙂
NSString * formatHHMMSSStringFromSeconds(int seconds)
{
    NSString *timeString = @"";
    int minutes = seconds / 60;
    seconds = seconds % 60;
    int hours = 0;
    if(minutes > 60)
    {
        hours = minutes / 60;
        minutes = minutes % 60;
    }
    timeString = [timeString stringByAppendingFormat:@"%02d:%02d:%02d",hours,minutes, seconds];
    return timeString;
}

svnX FileMerge does not work with XCode 4.3 upgrade

Many of us who upgraded their XCode to 4.3 must be facing an issue with FileMerge application which is part of svnX. After the XCode 4,3 upgrade, FileMerge application location has been changed. This is why it fails to launch from svnX.

You can fix this running the following command on terminal.
sudo /usr/bin/xcode-select-switch/Applications/Xcode.app/Contents/Developer

Also, you can launch the FileMerge directly from Xcode.
Xcode -> Open Developer Tool -> FileMerge.

The application binary can be found here:
/Applications/Xcode.app/Contents/Applications/FileMerge.app.

 

UIImage From Movie File

Simple utility method to create a image from video file. Specify the size of the image and the time interval.

UIImage *getImageFromMovieAtTime(AVURLAsset *videoAsset, CGSize imageSize,CMTime frameTime)
{
NSError *error =nil;
CMTime actualTime;


AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:videoAsset];
imageGenerator.appliesPreferredTrackTransform = YES;
imageGenerator.maximumSize = imageSize;
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:frameTime actualTime:&actualTime error:&error];
UIImage *movImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);

if(error || movImage == nil)
{
DEBUGLOG(@"Error: %@",error);
}
DEBUGLOG(@"imagesize: %@",NSStringFromCGSize(movImage.size));

return movImage;
}

Usage:

    UIImage *videoFrame = getImageFromMovieAtTime(videoAsset, CGSizeMake(width, height),kCMTimeZero);

Launching Map App on iOS to show route between source and destination location


+(void)showRouteOnMapFrom:(CLLocationCoordinate2D)sourceCoordinate to:(CLLocationCoordinate2D) destCoordinate
{
NSString* urlString = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f",
sourceCoordinate.latitude, sourceCoordinate.longitude,destCoordinate.latitude, destCoordinate.longitude];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}