Latest Mac OS X irrlicht framework + tutorial
Posted: Fri Jan 14, 2011 5:31 am
Linking the irrlicht library on OS X can be frustrating, and using a framework makes using irrlicht painless. Sadly there's no build target for making the latest irrlicht framework. So I made it.
Download irrlicht 1.7.1 debug framework
Download Xcode project files (put them in source/irrlicht/MacOSX/ and build the xcode project)
(Old debug only project here)
Making an app that requires no installer is now dead easy, and you can zip up and give to your .app to your friends.
Making an .app with an embedded framework in Xcode:
Create a new empty project (File > new project). Call it what you want.
Create a new build target (Project > new build target). We want a Cocoa Application.. Call it what you want.
You should see the target build settings. Remove the prefix header. Simply search for prefix header, double click the header files and press delete. Appkit.h will cause problems trying to build the application.
Now we add the irrlicht framework. Right click the build target and check add > exiting frameworks, and click add other. Go to where you downloaded the irrlicht framework and select it.
Next we will embed the framework with the app. This is so we don't have to make any installers or copying irrlicht.a in silly places.
Right click your project then select add > New Build Phase > New Copy Files Build Phase
Select Framework from the drop down menu and leave the text box blank. Then close the window.
Underneath your build target you should see Copy Files(1) build phase. While holding down OPTION, drag the irrlicht framework into the copy files build phase.
If you do this step wrong, you'll see this error:
We're almost ready to compile our irrlicht app. Right click "Compile Sources" and select new > New File. Then add a main.cpp file (remember to unselect "create main.h") and write a short tut.
Frameworks have their own file header folder, so we use some macro magic:
You can also create folders inside your app, so you don't have to rewrite large chunks of your code. If you drag a folder in there, you have the option of creating a reference or a real folder inside the app.
Note when you load in files, you have to navigate to the .app resource folder. You only have to do this once, with this code:
Hit compile, and you should get a irrlicht screen.
Edit: updated irrlicht xcode project to include both release and debug builds
Download irrlicht 1.7.1 debug framework
Download Xcode project files (put them in source/irrlicht/MacOSX/ and build the xcode project)
(Old debug only project here)
Making an app that requires no installer is now dead easy, and you can zip up and give to your .app to your friends.
Making an .app with an embedded framework in Xcode:
Create a new empty project (File > new project). Call it what you want.
Create a new build target (Project > new build target). We want a Cocoa Application.. Call it what you want.
You should see the target build settings. Remove the prefix header. Simply search for prefix header, double click the header files and press delete. Appkit.h will cause problems trying to build the application.
Now we add the irrlicht framework. Right click the build target and check add > exiting frameworks, and click add other. Go to where you downloaded the irrlicht framework and select it.
Next we will embed the framework with the app. This is so we don't have to make any installers or copying irrlicht.a in silly places.
Right click your project then select add > New Build Phase > New Copy Files Build Phase
Select Framework from the drop down menu and leave the text box blank. Then close the window.
Underneath your build target you should see Copy Files(1) build phase. While holding down OPTION, drag the irrlicht framework into the copy files build phase.
If you do this step wrong, you'll see this error:
Code: Select all
dyld: Library not loaded: @executable_path/../Frameworks/Irrlicht.framework/Versions/A/Irrlicht
Referenced from: /Users/username/Desktop/HelloWorld/HelloWorld/build/Debug/HelloWorld.app/Contents/MacOS/HelloWorld
Reason: image not found
Frameworks have their own file header folder, so we use some macro magic:
Code: Select all
#if defined(__APPLE__) || defined(MACOSX)
#include <Irrlicht/irrlicht.h>
#include <OpenGL/OpenGL.h>
#else
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#include "irrlicht.h"
#endif
using namespace irr;
int main () {
IrrlichtDevice *device = createDevice( video::EDT_OPENGL);
if (!device)
return EXIT_FAILURE;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
core::rect<s32>(10,10,260,22), true);
while(device->run()) {
driver->beginScene(true, true, video::SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
device->drop();
return EXIT_SUCCESS;
}
Note when you load in files, you have to navigate to the .app resource folder. You only have to do this once, with this code:
Code: Select all
#ifdef _IRR_OSX_PLATFORM_
device->getFileSystem ()->changeWorkingDirectoryTo ("HelloWorld.app");
device->getFileSystem ()->changeWorkingDirectoryTo ("Contents");
device->getFileSystem ()->changeWorkingDirectoryTo ("Resources");
#endif
Edit: updated irrlicht xcode project to include both release and debug builds