Page 1 of 1

Latest Mac OS X irrlicht framework + tutorial

Posted: Fri Jan 14, 2011 5:31 am
by pippy3
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.

Image

Create a new build target (Project > new build target). We want a Cocoa Application.. Call it what you want.

Image

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.

Image

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.

Image

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

Image

Select Framework from the drop down menu and leave the text box blank. Then close the window.

Image

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
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:

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;
}
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:

Code: Select all

#ifdef _IRR_OSX_PLATFORM_ 
   device->getFileSystem ()->changeWorkingDirectoryTo ("HelloWorld.app"); 
   device->getFileSystem ()->changeWorkingDirectoryTo ("Contents"); 
   device->getFileSystem ()->changeWorkingDirectoryTo ("Resources"); 
#endif
Hit compile, and you should get a irrlicht screen.

Edit: updated irrlicht xcode project to include both release and debug builds

Framework won't compile

Posted: Fri Mar 04, 2011 11:39 pm
by jpenguin

Code: Select all

[quote]
Build Irrlicht of project MacOSX with configuration Release

Ld build/MacOSX.build/Release/Irrlicht.build/Objects-normal/ppc/Irrlicht normal ppc
cd /Users/jpenguin/irrlicht-1.7.1/source/Irrlicht/irrlicht-framework-xcode-1.7.1
setenv MACOSX_DEPLOYMENT_TARGET 10.4
/Developer/usr/bin/g++-4.0 -arch ppc -dynamiclib -isysroot /Developer/SDKs/MacOSX10.4u.sdk -L/Users/jpenguin/irrlicht-1.7.1/source/Irrlicht/irrlicht-framework-xcode-1.7.1/build/Release -F/Users/jpenguin/irrlicht-1.7.1/source/Irrlicht/irrlicht-framework-xcode-1.7.1/build/Release -filelist /Users/jpenguin/irrlicht-1.7.1/source/Irrlicht/irrlicht-framework-xcode-1.7.1/build/MacOSX.build/Release/Irrlicht.build/Objects-normal/ppc/Irrlicht.LinkFileList -install_name @executable_path/../Frameworks/Irrlicht.framework/Versions/A/Irrlicht -mmacosx-version-min=10.4 -framework Carbon -framework Cocoa -framework OpenGL -single_module -compatibility_version 0 -current_version 0 -o /Users/jpenguin/irrlicht-1.7.1/source/Irrlicht/irrlicht-framework-xcode-1.7.1/build/MacOSX.build/Release/Irrlicht.build/Objects-normal/ppc/Irrlicht

ld: warning: object file compiled with -mlong-branch which is no longer needed. To remove this warning, recompile without -mlong-branch: /Developer/usr/bin/../lib/gcc/powerpc-apple-darwin10/4.0.1/crt3.o
Undefined symbols:
  "_IOServiceMatching", referenced from:
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
  "_IOIteratorNext", referenced from:
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
  "_IOServiceGetMatchingServices", referenced from:
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
  "_IOObjectRelease", referenced from:
      getJoystickDeviceInfo(unsigned int, __CFDictionary*, JoystickInfo*)in CIrrDeviceMacOSX.o
      getJoystickDeviceInfo(unsigned int, __CFDictionary*, JoystickInfo*)in CIrrDeviceMacOSX.o
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
  "_IORegistryEntryGetParentEntry", referenced from:
      getJoystickDeviceInfo(unsigned int, __CFDictionary*, JoystickInfo*)in CIrrDeviceMacOSX.o
      getJoystickDeviceInfo(unsigned int, __CFDictionary*, JoystickInfo*)in CIrrDeviceMacOSX.o
  "_IORegistryEntryCreateCFProperties", referenced from:
      getJoystickDeviceInfo(unsigned int, __CFDictionary*, JoystickInfo*)in CIrrDeviceMacOSX.o
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
  "_IOCreatePlugInInterfaceForService", referenced from:
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
  "_IOMasterPort", referenced from:
      irr::CIrrDeviceMacOSX::activateJoysticks(irr::core::array<irr::SJoystickInfo, irr::core::irrAllocator<irr::SJoystickInfo> >&)in CIrrDeviceMacOSX.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

[/quote]

Posted: Sat Mar 05, 2011 9:30 am
by pippy3
@jpenguin

I should have mentioned you need to comment out #define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ in IrrCompileConfig.h if you want to build irrlicht yourself.

The old xcode project was for debug only. I have made a one for release and debug since.

Or if don't want to compile for yourself, here's the 1.7.2 irrlicht framework release build (11mb)

Posted: Sun Mar 06, 2011 7:05 pm
by jpenguin
Thanks, it work, to bad Irrlicht doesn't 64-bit on the mac. I wonder how supertuxkart supports joysticks on the mac? They use Irrlicht (IrrFramework.framework)...

An xcode template for use withe the Irrlicht.framework is available here

Posted: Sun Mar 06, 2011 9:47 pm
by hybrid
You just have to link in the correct IO framework and joystick support works.

Posted: Mon Mar 07, 2011 9:05 am
by pippy3
hybrid wrote:You just have to link in the correct IO framework and joystick support works.
ah, I forgot about that. I think I've been told that before.

I don't know why it's not in the xcode project by default.

Posted: Mon Mar 07, 2011 12:48 pm
by hybrid
I think it was only changed in the SVN/trunk version, as it had so many changes. So Irrlicht 1.8 will come with a full project file for Apple systems then.

Posted: Mon Mar 07, 2011 6:31 pm
by jpenguin
In trunk, the xcode project hasn't been updated for 13months

Posted: Mon Mar 07, 2011 10:05 pm
by hybrid
I'm pretty sure that I updated the project some time ago. Maybe it's more than a year, yeah.

Posted: Tue Mar 08, 2011 5:04 am
by pippy3
If it's any consolation, I've got irrlicht fullscreen working without carbon.

Bitplane asked me to do some things before he left and I've been chipping away at them. I want to get software rendering working and automatic .app directory finding working right before I submit them.

While removing carbon I came read about a 10.4 bug that required carbon to remove the docking bar. I inserted code that should fix it, but I can't test it. I did have a friend running 10.4 but he's since upgraded.

There was mention of a fix being released in a minor version, but that's why I'd want to test it.

Posted: Wed Mar 16, 2011 9:30 pm
by jpenguin
So, with 1.8 will there be an XCode project included that allows compiling as a framework; with 64bit support (no carbon)

@pippy3-- what do you mean by "automatic"; can't you just include my XCode templates and call it good?

My Website

Hello World example

Posted: Wed Mar 16, 2011 9:59 pm
by hybrid
Framework compilation had been provided by bitplane some time ago. The carbon free version is not yet made.