Note:
You no longer have to compile your own version of Ogre, I have made my own deb packages available here.
First add the key
Copy and paste this in the terminal
Code:
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 6FED7057
Then go to System->Administration->Software Sources. Click on the "Third Party Software" Tab and then click the "Add" button.
Replace the word "jaunty" with your version of Ubuntu below and add these repos.
Code:
deb http://ppa.launchpad.net/andrewfenn/ogredev/ubuntu jaunty main
Code:
deb-src http://ppa.launchpad.net/andrewfenn/ogredev/ubuntu jaunty main
After you have done that click close.
You can now get updates for the latest stable release of Ogre and CEGUI.
If you wish to compile Ogre yourself then keep reading below.
Introduction
Ogre3d and a graphics rendering engine that one can use in either your game or 3d graphics program. It's under a dual license, the source is available under the LGPL but you can also purchase a commercial license for companies do not want to share additions to the Ogre Engine, or need technical support.
This is a newish "how to" on getting everything set up so you can start making your games on Ubuntu using the latest version of Ogre3D and CEGUI. Before you start you might want to have a quick read of the getting started with Ogre guide to make sure Ogre3d is the graphics engine you want to use.
Why compile yourself?
- Ogre in the repositories is always an old version, this makes any development work difficult especially if you're trying to integrate code for specific versions of packages.
- The package for Ogre is taken from Debian that means they have taken out support for cg which is not recommended. It also builds with support for the old openexr implementation rather then use freeimage support.
- The packages for CEGUI are broken. It is impossible with the packages in Ubuntu to load up ogre's scheme files using CEGUI as they have not been built correctly.
If none of these are problem for you then please go ahead and use the repositories, but I don't feel that's the case for most Ogre uses. The above problems all have bugs filed on launchpad.
OK, lets do it
First you're going to want to install the following packages.
Code:
sudo apt-get install build-essential libois-dev
Build-Essential gives you everything you need to compile your programs. libois is the Open Input System which is used in the Ogre and CEGUI samples. If you're not using libOIS in your program then there is no need to install it although you might need to change some options in the ./configure if you don't.
We're going to start by building some packages and then I'll show you a sample makefile at the end you can use.
Building FreeImage
First I like to start by adding the latest version of FreeImage as the packages for Ubuntu are always out of date. First go to FreeImage's website, then go to the download link and get the "Source distribution".
When you have downloaded that, unzip it, cd into the directory and type:
followed afterwards by
Building CEGUI
Next we will install CEGUI. If you're not going to use Crazy Eddies GUI in your program you can skip this step.
The way Ubuntu packages CEGUI is incorrect if you want to use it with Ogre3D's default schemes. To correct this we need to download and build CEGUI ourselves.
For building CEGUI you're going to need to first install the following packages.
Code:
sudo apt-get install libfreetype6-dev libpcre3-dev
Go to the CEGUI download page and get the latest stable branch of "CEGUI Library Source Downloads". It will be marked as the one for Linux users.
So unzip it ,cd into the directory and type the following.
Code:
./configure --with-default-xml-parser=TinyXMLParser --with-default-image-codec=FreeImageImageCodec
It will check that you have everything you need then give you the message "Now you can do make && make install. Good Luck!"
Do what it says, don't forget to add "sudo" to your "make install".
Building Ogre3d
To so now we're going to build Ogre3D. Go and download the version of Ogre you want to use. I suggest the current stable package. Make sure you download the "Linux / OSX" package.
First you're going to need to install a few packages to get Ogre building.
Code:
sudo apt-get install autoconf automake libtool libzzip-dev libxt-dev libxaw6-dev libxxf86dga-dev libxxf86vm-dev libxrandr-dev nvidia-cg-toolkit libglu1-mesa-dev
Again, unzip it, cd into the directory and type the following..
Code:
./bootstrap
./configure
make
sudo make install
After you have compiled and installed Ogre on your system use the following command to make the library you just installed work.
You should also now be able to run the demos if you built them. They are located in /ogre/samples/common/bin, with "/ogre" being the directory you extracted the source from.
- Makefile - So you have done all that and want to start coding.
I suggest you layout your folders directory structure like this..
Code:
./yourgame/Makefile
./yourgame/src
./yourgame/include
./yourgame/media
./yourgame/bin
./yourgame/cmake/modules
You put your .cpp file into the src directory, your .h files will go into include and Ogre's media directory will be put into media. The bin directory will be where your compiled program goes, in that file you're going to need "Ogre.cfg", "plugins.cfg", "resources.cfg" which you can get from an example Ogre app.
If you compiled Ogre yourself you're going to need to change "PluginFolder" in Plugins.cfg to the following..
Code:
PluginFolder=/usr/local/lib/OGRE/
Compiling your own Ogre programs
So you've installed your dependencies, maybe you have some code already, how do you compile, link and run it? Well let me introduce you to cmake.
cmake is a program which will generate Makefiles for you, it's actually much more then this. It will generate visual studio programs, code::blocks, xcode, MinGW, whatever compiler or IDE you use to program in it will probably do it and all you have to do is type "cmake ."
To set cmake up you need to write a script for it.
I suggest looking at my cmake script as well as the FindOGRE module you will need.
Setting up cmake can be difficult at first, but it's very much worth it for the ease of just typing cmake . to setup your build environment.
Here is a stripped down version of my script. Put this is in ./yourgame/CMakeLists.txt
Code:
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
#Change PROJECT_NAME to the name of your project
PROJECT(Project)
# Change to whatever version your project is at
SET( ${PROJECT_NAME}_MAJOR_VERSION 0 ) # < -- Something completely different from old version
SET( ${PROJECT_NAME}_MINOR_VERSION 1 ) # < -- Incompatable with old versions
SET( ${PROJECT_NAME}_PATCH_LEVEL 4 ) # < -- Minor fix
SET( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules )
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#Declare any external dependencies that your project may have here.
SET(Required_Packages
OIS
OGRE
CEGUI
CEGUIOGRE
)
# searches for all .cpp and .h files in the current directory and add them
# to the current project
FILE(GLOB folder_source ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
SOURCE_GROUP(${Project} FILES ${folder_source})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
IF (NOT WIN32) # Unix
# Add compiler warnings ( Warn all, warn unused)
ADD_DEFINITIONS( "-Wall -Wunused -ansi" )
ENDIF (NOT WIN32)
# create the project (Note WIN32 here will be ignored on linux, it means set to be
# windows application instead of a console application)
ADD_EXECUTABLE(${Project} WIN32 ${folder_source})
#this foreach loads all of the packages that you specified as required.
#It shouldn't need to be modified.
FOREACH(Package ${Required_Packages})
FIND_PACKAGE(${Package} REQUIRED)
IF (${Package}_FOUND)
INCLUDE_DIRECTORIES(${${Package}_INCLUDE_DIR})
IF (${Package}_LIBRARIES)
TARGET_LINK_LIBRARIES(hardwar ${${Package}_LIBRARIES})
ELSE (${Package}_LIBRARIES)
LINK_DIRECTORIES(${${Package}_LIBRARY_DIRS})
ENDIF (${Package}_LIBRARIES)
ELSE (${Package}_FOUND)
MESSAGE(STATUS "${Package} not found")
ENDIF(${Package}_FOUND)
ENDFOREACH(Package)
Making a program in Ogre
To start coding in Ogre3d Check out the Basic Tutorials and build your way up from there.
Further Reading
Here is some further reading I recommend in coding on Linux using Ogre3d.
Setting up an application - Deals with setting up your Ogre3d application and compiling it.
Build FAQ - Deals with some problems people have compiling their programs with Ogre.
Other Stuff you might want to look at
Navi - A different User Interface API for Ogre
FXpression - A particle engine which has a plugin for Ogre
Bullet - A physics engine which can be plugged into Ogre
Optimizing Your C/C++ Applications - Part 1 and Part 2
I hope this helps some people.
Bookmarks