BHM skinning sample running on OS X

Although the sample for the BHM file format was designed to run on many platforms, including Windows, *nix and OS X, I had never actually tested the code on OS X yet. There were no provisions made in the code, it was just assumed to work on OS X, since OS X is based on BSD, and supports OpenGL and X11.

Now that I had made a first release package for the project, I was wondering if it actually worked on OS X. A fellow who goes by the nickname of SpooK was kind enough to test the code, and after a few minor tweaks, he got it running on his Mac. I merged the few suggestions he made, so that the code would compile on OS X out-of-the-box.

However, he didn’t stop there… The code now worked, but was still dependent on the X11 layer, where OS X can also support OpenGL natively through the Quartz layer. He made a few changes to remove the X11 dependencies and replace them with the native OS X OpenGL/GLUT framework. The result was that the application started much faster, and also got considerably better framerates. So it’s worth the trouble.

At this point I wanted to get my hands on OS X myself, to play around with it. I also wanted to see if I could make a binary that works out-of-the-box, as with the Windows version (should be much easier for OS X than for your average linux or FreeBSD installation, since OS X has only one distributor, who distributes it in binary form, much like with Windows).

So I used an OS X installation from VMWare on my machine. And I tried to set it up with the proper development tools. One the one hand, OS X is completely foreign to me, as far as development goes, and it doesn’t look much like the environments that I am used to. But on the other hand, it’s pretty clean, and the Apple developer site gave me enough to go on.

Before long, I had it working:

Then I tried to make a downloadable binary for it, which can run out-of-the-box. That was a bit of a problem, since I had to build FreeImage and GLEW via MacPorts. I had to somehow package these libraries in a way that they didn’t require any installing (MacPorts is like ports on FreeBSD, but the problem is that OS X doesn’t come with a compiler by default. You have to install Xcode first, which is a bit much to ask for just a simple sample).

So I looked into the .app bundle system that OS X supports. It allows you to bundle your executable with data resources and libraries/frameworks in a simple way. Basically a .app  is just a regular folder, with a specific structure. The OS makes it appear as a single application file. The problem I had however, was that my binary was linked to the FreeImage and GLEW libraries with absolute paths. So it wouldn’t look in the .app folder.

I found a solution to that problem in the form of some python scripts by the name of macholib (Mach-O is the name of Apple’s executable format, much like PE/COFF on Windows or ELF on many *nix systems).

Macholib can take your .app, scan for the dynamically linked libraries it uses and copy them into the Frameworks subfolder of your .app. Then it will rewrite the headers of your executable so that the absolute paths will become relative paths, pointing to the Frameworks subfolder of your .app. Now you can easily redistribute your .app without any installation required. It is fully self-contained.

The BHM 3D Sample for Mac OS X x86 can be downloaded here: http://bohemiq.scali.eu.org/BHM3DSample.zip

Advertisements
This entry was posted in OpenGL, Software development, Software news. Bookmark the permalink.

2 Responses to BHM skinning sample running on OS X

  1. Pingback: Porting BHM3DSample to iPhone: some Objective-C++ and OpenGL ES development | Scali's blog

  2. Pingback: The problem with free/open source software | Scali's OpenBlog™

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s