Introduction

This section should show you how to configure an empty Xcode 4 project to use with Ogre. You will specify anything yourself and hence gain some knowledge in what you need to link and where your application will look for files.

Prerequisites

  • Install dependencies. MacPorts is recommended. Prerequisites
  • You have a running OgreSDK (if not, go to Installing the Ogre SDK) placed in /Developer/SDKs/OgreSDK.
  • Nvidia's CG Framework is installed in /Library/Frameworks (this is the default path, details can be found in the Installing the Ogre SDK page).

Let's go

Step 1: Create an new Xcode project

In Xcode, go to File | New | New Project... and select "Cocoa Application" as project template. Give the project any name you like and save it. I will call it MyOgreProject and use this name throughout this tutorial.

Create new Xcode project (options) Create new Xcode project (template)

This will create a folder named "MyOgreProject" inside your project folder. Rename it to "Resources" and remove everything in it except the .plist file. You can remove the references to these files in Xcode.

Step 2: Change the build settings

Go to the project's build settings and change the following entries:

  • Base SDK: Current Mac OS
  • Other Linker Flags: "$(DEVELOPER_DIR)/SDKs/OgreSDK/lib/release/libOIS.a"
  • Framework Search Paths: "$(DEVELOPER_DIR)/SDKs/OgreSDK/lib/release"
  • Header Search Paths: "$(DEVELOPER_DIR)/SDKs/OgreSDK/boost_1_46_1" "$(DEVELOPER_DIR)/SDKs/OgreSDK/include/OIS" "$(DEVELOPER_DIR)/SDKs/OgreSDK/include/OGRE" "$(DEVELOPER_DIR)/SDKs/OgreSDK/include/OGRE/OSX"

Change project build settings


Go to the target's build settings and change the following entries:

  • Info.plist File: Resources/MyOgreProject-Info.plist
  • GCC_PREFIX_HEADER: "" delete this entry

Change target build settings

Step 3: Add source files to your project

Download the Ogre Wiki Tutorial Framework and add all .h and .cpp files to your project.

In BaseApplication.h add the following line to the include statements:

#include <macUtils.h>

This will make the Ogre::macBundlePath() available for us (see below).
(Note: You might have to specify OSX/macUtils.h)

In TutorialApplication.cpp overwrite the createScene function with the one from Basic Tutorial 1 and add these lines right to the beginning of the main function (around line 60):

Ogre::String workingDir = Ogre::macBundlePath()+"/Contents/Resources";
chdir(workingDir.c_str());
std::cout << "working directory: "+workingDir+"\n";

We tell the application to change the working directory to the Resources folder inside the App bundle. All resources will be placed there.

Step 4: Add the config files

Add these files to the Resources folder:

plugins.cfg
#Defines plugins to load

#Define plugin folder
PluginFolder=

#Define plugins
#Plugin=RenderSystem_Direct3D9
#Plugin=RenderSystem_Direct3D10
#Plugin=RenderSystem_Direct3D11
Plugin=RenderSystem_GL
#Plugin=RenderSystem_GLES
Plugin=Plugin_ParticleFX
Plugin=Plugin_BSPSceneManager
Plugin=Plugin_CgProgramManager
Plugin=Plugin_PCZSceneManager
Plugin=Plugin_OctreeZone
Plugin=Plugin_OctreeSceneManager
resources.cfg
# Resources required by the sample browser and most samples.
[Essential]
Zip=/Developer/SDKs/OgreSDK/Media/packs/SdkTrays.zip
FileSystem=/Developer/SDKs/OgreSDK/Media/thumbnails

# Common sample resources needed by many of the samples.
# Rarely used resources should be separately loaded by the
# samples which require them.
[Popular]
FileSystem=/Developer/SDKs/OgreSDK/Media/fonts
FileSystem=/Developer/SDKs/OgreSDK/Media/materials/programs
FileSystem=/Developer/SDKs/OgreSDK/Media/materials/scripts
FileSystem=/Developer/SDKs/OgreSDK/Media/materials/textures
FileSystem=/Developer/SDKs/OgreSDK/Media/materials/textures/nvidia
FileSystem=/Developer/SDKs/OgreSDK/Media/models
FileSystem=/Developer/SDKs/OgreSDK/Media/particle
FileSystem=/Developer/SDKs/OgreSDK/Media/DeferredShadingMedia
FileSystem=/Developer/SDKs/OgreSDK/Media/PCZAppMedia
FileSystem=/Developer/SDKs/OgreSDK/Media/RTShaderLib
FileSystem=/Developer/SDKs/OgreSDK/Media/RTShaderLib/materials
Zip=/Developer/SDKs/OgreSDK/Media/packs/cubemap.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/cubemapsJS.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/dragon.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/fresneldemo.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/ogretestmap.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/ogredance.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/Sinbad.zip
Zip=/Developer/SDKs/OgreSDK/Media/packs/skybox.zip

[General]
FileSystem=/Developer/SDKs/OgreSDK/Media


Step 5: Add the make file

This make file copies the required frameworks, components, plugins and resources to the app bundle:

CopyFiles.make
OGRE_SDK=/Developer/SDKs/OgreSDK

all:
	# create directories (if they don't exist)
	mkdir -p $(CONTENT_PATH)/Components
	mkdir -p $(CONTENT_PATH)/Plugins
	mkdir -p $(CONTENT_PATH)/Resources
	mkdir -p $(CONTENT_PATH)/Frameworks

	# copy components
	cp $(OGRE_SDK)/lib/libOgrePaging.dylib $(CONTENT_PATH)/Components
	cp $(OGRE_SDK)/lib/libOgreProperty.dylib $(CONTENT_PATH)/Components
	cp $(OGRE_SDK)/lib/libOgreRTShaderSystem.dylib $(CONTENT_PATH)/Components
	cp $(OGRE_SDK)/lib/libOgreTerrain.dylib $(CONTENT_PATH)/Components

	# copy plugins
	cp $(OGRE_SDK)/lib/Plugin_BSPSceneManager.dylib $(CONTENT_PATH)/Plugins
	cp $(OGRE_SDK)/lib/Plugin_CgProgramManager.dylib $(CONTENT_PATH)/Plugins
	cp $(OGRE_SDK)/lib/Plugin_OctreeSceneManager.dylib $(CONTENT_PATH)/Plugins
	cp $(OGRE_SDK)/lib/Plugin_OctreeZone.dylib $(CONTENT_PATH)/Plugins
	cp $(OGRE_SDK)/lib/Plugin_PCZSceneManager.dylib $(CONTENT_PATH)/Plugins
	cp $(OGRE_SDK)/lib/Plugin_ParticleFX.dylib $(CONTENT_PATH)/Plugins
	cp $(OGRE_SDK)/lib/RenderSystem_GL.dylib $(CONTENT_PATH)/Plugins
	
	# copy frameworks
	cp -R /Library/Frameworks/Cg.framework $(CONTENT_PATH)/Frameworks/
	cp -R $(OGRE_SDK)/lib/release/Ogre.framework $(CONTENT_PATH)/Frameworks/
	
	# copy resource files
	cp -R Resources/* $(CONTENT_PATH)/Resources/
	
	# change permission on all files
	chmod -R u+rwx $(CONTENT_PATH)/*
	chmod -R go+r $(CONTENT_PATH)/*

clean:
	rm -rf $(CONTENT_PATH)/Components
	rm -rf $(CONTENT_PATH)/Plugins
	rm -rf $(CONTENT_PATH)/Resources
	rm -rf $(CONTENT_PATH)/Frameworks


Step 6: Configure the build phases

In Xcode again, go to the build phases of your MyOgreProject target. Remove the Cocoa.framework from the "Link Binary With Libraries" phase and add the following frameworks instead:

  • Carbon.framework
  • Cocoa.framework
  • OpenGL.framework
  • AGL.framework
  • CoreVideo.framework
  • IOKit.framework
  • Cg.framework
  • Ogre.framework (from /Developer/SDKs/OgreSDK/lib/release)


Remove the "Copy bundle resources" build phase and add a new "Run Script" phase with the following code:

make -C $SRCROOT -f $SRCROOT/CopyFiles.make CONTENT_PATH=$BUILD_DIR/$CONFIGURATION/$CONTENTS_FOLDER_PATH clean
make -C $SRCROOT -f $SRCROOT/CopyFiles.make CONTENT_PATH=$BUILD_DIR/$CONFIGURATION/$CONTENTS_FOLDER_PATH all

Build phases

Step 7: Build

The project should now build without errors. If so, try to run the application. You should see the green Ogre head from Basic Tutorial 1.
Rendering of the first Basic Tutorial

Todo

  • Add troubleshooting section (once a problem is reported)