Aug 23, 2008

Installing OGRE on Ubuntu

I've been messing around with this C++ library called Ogre, which is a fancy 3D rendering library. It's great for building cross-platform 3D applications where you don't want to have to worry about a lot of the lower level details of 3D programming.

I found that it was a bit of a pain to install on Ubuntu. You can get the packages in Synaptic, but sometimes they are out of date, or there are a few libraries that work together but different versions are incompatible, etc. So I decided the best option was to roll up my sleeves and compile it on my own.

Here's what you have to do: get CEGUI, Cg and OIS. CEGUI is a widget library designed for 3D applications. It's not required for OGRE, but I think it is definitely a good thing to have. OIS is an input system, you use it to interact with the keyboard/mouse/joystick/etc. You can also use SDL for this, but SDL comes with a whole lot of other stuff that you may or may not need. Cg is Nvidia's shader language, from what I've gathered the Ogre guys highly recommend it.
You'll have to compile these guys from source, using the old ./configure + make + make install routine. No big deal. If there is no configure file, then use ./bootstrap first.
One problem with using CEGUI from the Ubuntu repositories is that it is set to use the Xerces XML parsing library. Unfortunately for some reason there are some issues with this, so you have to compile CEGUI yourself and tell it not to use Xerces. It'll probably default to Expat (another XML parsing library) which works well. Use this line instead of the normal ./configure:
./configure --disable-xerces-c
and off you go. OIS should install without any problems, as should Ogre. Cg doesn't even need to compile, you just copy the tarball to the root directory and extract it.

Once you've got everything installed, you might have some issues getting things to compile. Type this:
pkg-config --cflags OGRE OIS CEGUI
It should output something like this:
-I/usr/local/include/OGRE -I/usr/local/include/OIS
These are the include paths to the libraries you just installed, and you'll need to use those flags when you compile your OGRE program. So when you create your makefile, put
CXXFLAGS = `pkg-config --cflags OGRE OIS CEGUI`
LFLAGS = `pkg-config --libs OGRE OIS CEGUI` -lCEGUIOgreRenderer
You have to put the -lCEGUIOgreRenderer if you're using CEGUI, it's the way Ogre and CEGUI communicate with one another.

One final hiccup is that Ubuntu doesn't know where to look for the shared object (.so) files once you've gotten your program to compile. They are in /usr/local/lib, but Ubuntu normally puts things in /usr/lib. So you have to edit /etc/ file and add the line:
at the end. You only need to do this if you have issues with your Ogre app loading the shared objects.

And finally, you need to tell Ogre where to find the plugins. In your plugins.cfg file in the folder where your Ogre app is, make sure that the PluginFolder value is set to /usr/local/lib/OGRE.

Once you have all this going, there are some very well-written tutorials on the Ogre wiki. You should have some good stuff up and running in no time!

1 comment:

Calder said...

I wrote a tutorial for this on the Ubuntu forums if you're still interested. Here's the link