Skip to content
Tags

Compiling for OpenSceneGraph in Mac

November 24, 2010

In my previous post I showed how to install OSG 2.8.2 in Mac. Now I want to explain just a couple basic issues to compile a simple program.

In OpenSceneGraph there is not a one-for-all big header you have to include when you want something from OSG. Your headers will have a bunch of inclusions instead. ¿Is this bad? Well… you have to write a few more lines just one time, but the compilation will be much faster, saving you many precious minutes or hours of your life.

One thing you have to take into account is that OSG is still not ready for 64 bits in Mac for several reasons, so keep it i386 for now.

Finally, here is how to make it work for CMake and Xcode. You can download this toy material and play around:

my_osgplanets.zip

CMake

Some advise if you compile for CMake:

  1. Set the variable CMAKE_OSX_ARCHITECTURES to i386.
  2. You have to include both OpenThreads and OpenSceneGraph with the packages needed.

That is:
set(CMAKE_OSX_ARCHITECTURES i386)
FIND_PACKAGE(OpenThreads REQUIRED)
FIND_PACKAGE(OpenSceneGraph REQUIRED osgGA osgUtil osgDB osgViewer)

To compile using CMake (assuming you have it installed, of course):

cd /to/your/project/
mkdir build_cmake #or any other name
cd build_cmake
cmake ..
make
./osgplanets

As you can see, it is quite easy and extremely clean because everything is under your build directory, which can be anywhere.

Xcode

The equivalent for Xcode is to set i386 in the overview panel, and include the OpenThreads and osg frameworks, as well as any other framework for extra OSG modules.

You have a small example to play with, using the code taken from the osgplanets example from the OSG source code. There are compilation methods for CMake and an original Xcode project.

To compile with Xcode, just press the Build button. If you Build & Go, you will probably notice that there are no textures. That is because Xcode executes it without the variable OSG_FILE_PATH you should have in your .bash_profile. If you run the executable from the terminal, or double click the icon, it will work ;)

This should be the result.

osgplanets.png

Advertisement

From → Tips

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.