Building and running Ogre3D demo samples on the iMX6-REX

Hello iMX6-Rex fans,

You may have read my short introduction to the Ogre3D open source video game engine running on the iMX6-Rex board. On this page I explain how you can build and run this game engine on the iMX6-Rex board.

If you are used to building your demos, Apps, or generally your code on a PC host and then running it on a target platform such as the iMX6-Rex (a process that is called cross-compiling) then the steps explained on this page will be new for you. Thanks to the vast number of open source tools (such as the GNU Compiler Collection) that are now available for ARM powered computers, we are able to build our demo directly on this board and without the need for a separate computer. This also eliminates the need to transfer compiled files over to the target device every time we have a new build.

So, how do we do this? We will start the process assuming that a suitable file system with suitable configurations is installed on your board. By suitable, I mean having the X11 integration with the GPU, having working GPU drivers available, and preferably running a X11 desktop at a reasonable resolution. My preferred resolution for this demo is 640×480. Although the iMX6-Rex is capable of running 1080p HD resolution, a lower resolution allows for a much faster interaction with the board in case you are connecting to the board remotely.

You might be asking where you can obtain such a file system. Well you are not entirely out of luck. We already have a ready-made file system which you can read about on this page:
In the future, we will explain how you can achieve this integration for any Linux file system so that you can produce your own versions.

Please also make sure that your storage device is not smaller than 4Gb. Ogre3D was originally designed for resourceful desktop computers and so building and running it requires a lot of storage space! So make sure you have enough storage space before jumping into the build process :)

Once you have managed to boot your board and log into the Ubuntu, you will need to follow the steps below to build your own version of the Ogre3D engine and demos:

1- Setting up the display and running the X11 desktop:

Assuming that you are the “root” user:

insmod /lib/modules/3.0.35-03023-gc1bed09-dirty/kernel/drivers/gpu/drm/vivante/vivante.ko
cp -ra /home/ubuntu/.X* /home/ubuntu/.x* /root/
export DISPLAY=:0.0
startx &
xhost localhost

Please note that you should change the destination path in the second command according to your user’s home directory. For the “root” user this is /root/

The insmod command is also essential for our purposes because without the right driver module, the display server laucnhed via startx will not be GPU accelerated. To test that your driver works correctly please find and run one of Vivante’s own demos to make sure that the demo runs smoothly and at a reasonable performance with the following commands:

cd /root/gpu-viv-bin-mx6q-3.10.9-1.0.0-hfp/opt/viv_samples/tiger/

In my test, the console output from this demo was:

id=64, a,b,g,r=0,5,6,5, d,s=16,0, AA=0,openvgbit=23
frames:100 — fps:161.290329

Therefore if you cannot run this demo or if the reported FPS is significantly lower than 161, then you may have a problem with your drivers and/or your board.

2- Installing required libraries:

Install all the libraries that are required by the Ogre3D build system. Note that some optional libraries may be platform specific and may not be available for the ARM architecture. However, these libraries are optional and not mandatory for building Ogre3D. Yes, the list is long and consumes a lot of your storage. But don’t forget that Ogre3D was originally designed for resourceful desktop computers!

sudo add-apt-repository ppa:ogre-team/ogre
sudo apt-get update
apt-get install cmake cmake-curses-gui mercurial meld libxrandr-dev libglu1-mesa-dev libzip-dev libfreeimage-dev libpoco-dev libois-dev libogre-1.7.4 libogre-dev libzzip-0-13 libzzip-dev doxygen libcgal-dev libcppunit-dev vim

Note that the first line is required because we are installing the Ogre3D dependency packages suitable for this ARM target from a location that is not known to Ubuntu by default.

As an advanced footnote, depending on your filesystem you may need to fix some of the OpenGL-ES library paths. For example make sure that /usr/lib/arm*hf/ points to the right Vivante shared object on your file system.

3- Downloading the Ogre3D 1.7 source code:

In order to download the source code run the following command in a suitable path. Note that it downloads all the source files into a new subdirectory called ogre:

cd /root/
hg clone -u v1-7

This step may take a while as it will be downloading the many Ogre3D source files from the Internet. Once it is done, you should have the full Ogre3D 1.7 source code under “/root/ogre/”.

4- Modifying the source code to match the platform:

You will have to make a number of modifications to the source code to enable the build system to complete successfully.

In the file “/root/ogre/OgreMain/src/OgrePlatformInformation.cpp” find the line where the header file “machine.h” is included and comment out that line:

    #include <sys/sysctl.h>
//  #include <mach/machine.h>

In the same file, find and comment out the following four lines:

//  static int mib[] = { CTL_HW, HW_MODEL };
//  if (sysctl (mib, 2, processor, &s, 0, 0) >= 0)
//  cpuID = processor;
//  else

Note that you can use the tool “vim” to edit files on your platform. We have already installed this tool in the steps above. If you are not familiar with this tool then please find references online or install and use the editing tool with which that you are comfortable.

5- Configuring and building from the source code:

Once the download process in step 3 is complete, you can begin to configure and build the source code. This needs to be done in a separate directory under the source code directory:

cd /root/ogre/
mkdir bld
cd /root/ogre/bld


make -j1

You may be wondering what the “-j1″ argument does. Make has the ability to build several files at the same time using multithreading. However, we have experienced issues with this. So using no arguments or arguments such as “-j4″ to utilise all four CPU cores may cause internal errors in the GCC. One of the reasons could be due to the fact that the GCC toolchain itself was not built on the target. This, often, can be the cause of such unexpected issues when moving from one device to another.

For your information, a typical output from the cmake command above would look like the following:

– The C compiler identification is GNU 4.7.3
– The CXX compiler identification is GNU 4.7.3
– Check for working C compiler: /usr/bin/cc
– Check for working C compiler: /usr/bin/cc — works
– Detecting C compiler ABI info
– Detecting C compiler ABI info – done
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ — works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info – done
– Configuring OGRE 1.7.4
– Check size of void*
– Check size of void* – done
– Performing Test OGRE_GCC_HAS_SSE
– Performing Test OGRE_GCC_HAS_SSE – Failed
– Performing Test OGRE_GCC_VISIBILITY – Success
– Detected g++ 4.7
– Enabling GCC visibility flags
– Check if the system is big endian
– Searching 16 bit integer
– Looking for sys/types.h
– Looking for sys/types.h – found
– Looking for stdint.h
– Looking for stdint.h – found
– Looking for stddef.h
– Looking for stddef.h – found
– Check size of unsigned short
– Check size of unsigned short – done
– Using unsigned short
– Check if the system is big endian – little endian
– Search path: /root/ogre/bld/Dependencies;/root/ogre/Dependencies
– Looking for ZLIB…
– Found PkgConfig: /usr/bin/pkg-config (found version “0.26″)
– checking for module ‘zzip-zlib-config’
– found zzip-zlib-config, version
– Found ZLIB: optimized;/usr/lib/arm-linux-gnueabihf/;debug;/usr/lib/arm-linux-gnueabihf/
– Looking for ZZip…
– checking for module ‘zziplib’
– found zziplib, version 0.13.56
– Found ZZip: optimized;/usr/lib/;debug;/usr/lib/
– Looking for FreeImage…
– checking for module ‘freeimage’
– package ‘freeimage’ not found
– Found FreeImage: optimized;/usr/lib/;debug;/usr/lib/
– Looking for FREETYPE…
– checking for module ‘freetype2′
– found freetype2, version 16.0.10
– CMAKE_PREFIX_PATH: /root/ogre/bld/Dependencies;/root/ogre/Dependencies;/usr/local
– Found FREETYPE: optimized;/usr/lib/arm-linux-gnueabihf/;debug;/usr/lib/arm-linux-gnueabihf/
– Looking for XOpenDisplay in /usr/lib/arm-linux-gnueabihf/;/usr/lib/arm-linux-gnueabihf/
– Looking for XOpenDisplay in /usr/lib/arm-linux-gnueabihf/;/usr/lib/arm-linux-gnueabihf/ – found
– Looking for gethostbyname
– Looking for gethostbyname – found
– Looking for connect
– Looking for connect – found
– Looking for remove
– Looking for remove – found
– Looking for shmat
– Looking for shmat – found
– Looking for IceConnectionNumber in ICE
– Looking for IceConnectionNumber in ICE – found
– Found X11: /usr/lib/arm-linux-gnueabihf/
– Found OpenGL: /usr/lib/arm-linux-gnueabihf/
– Looking for Cg…
– Cg_PREFIX_PATH changed.
– checking for module ‘Cg’
– package ‘Cg’ not found
– Could not locate Cg
– Looking for POCO…
– checking for module ‘POCO’
– package ‘POCO’ not found
– Found POCO: optimized;/usr/lib/;debug;/usr/lib/
– Looking for POCO_Util…
– Found POCO_Util: optimized;/usr/lib/;debug;/usr/lib/
– Looking for POCO_Net…
– Found POCO_Net: optimized;/usr/lib/;debug;/usr/lib/
– Looking for POCO_NetSSL…
– Found POCO_NetSSL: optimized;/usr/lib/;debug;/usr/lib/
– Looking for POCO_XML…
– Found POCO_XML: optimized;/usr/lib/;debug;/usr/lib/
– Looking for TBB…
– Could not locate TBB
– Looking for OIS…
– OIS_PREFIX_PATH changed.
– checking for module ‘OIS’
– found OIS, version 1.3.0
– Found OIS: optimized;/usr/lib/arm-linux-gnueabihf/;debug;/usr/lib/arm-linux-gnueabihf/
– Found Doxygen: /usr/bin/doxygen
– Looking for CppUnit…
– checking for module ‘cppunit’
– found cppunit, version 1.12.1
– Found CppUnit: optimized;/usr/lib/;debug;/usr/lib/

– The following external packages were located on your system.
– This installation will have the extra features provided by these packages.
+ zlib
+ zziplib
+ freeimage
+ freetype
+ X11
+ Xt
+ Xaw
+ OpenGL
+ OpenGL ES
+ boost
+ boost-thread
+ boost-date_time
+ Doxygen
+ CppUnit
– The following OPTIONAL packages could NOT be located on your system.
– Consider installing them to enable more features from this software.
+ cg: C for graphics shader language <>
+ tbb: Threading Building Blocks <>

Building components:
+ Paging
+ Property
+ Terrain
+ RTShader System
+ RTShader System Core Shaders
+ RTShader System Extensions Shaders
Building plugins:
+ BSP scene manager
+ Octree scene manager
+ Portal connected zone scene manager
+ Particle FX
Building rendersystems:
+ OpenGL
Building executables:
+ Samples
Building core features:
+ DDS image codec
+ FreeImage codec
+ ZIP archives
Build type: dynamic
Threading support: none
Use double precision: disabled
Allocator type: nedmalloc (pooling)
STL containers use allocator: enabled
Strings use allocator: disabled
Memory tracker (debug): disabled
Memory tracker (release): disabled
Use new script compilers: enabled
Use Boost: enabled
– Configuring done
– Generating done
CMake Warning:
Manually-specified variables were not used by the project:
– Build files have been written to: /root/ogre/bld

The make command will be slow so you will have to be patient while it is building the huge game engine for you. The output will look something like the following:

Scanning dependencies of target OgreMain
[ 0%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAlignedAllocator.cpp.o
[ 0%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAnimable.cpp.o
[ 0%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAnimation.cpp.o
[ 1%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAnimationState.cpp.o
[ 1%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAnimationTrack.cpp.o
[ 1%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreArchiveManager.cpp.o
[ 1%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreAutoParamDataSource.cpp.o

As an advanced footnote, be aware that if something breaks the build process ( for example, a power outage!) then you can just resume the process from where it was left off by just running the “make -j1″ command from the same build directory “/root/ogre/bld/”.

6- Running Ogre3D!

If all the above steps complete successfully, you will be able to run the Ogre3D demos:

cd /root/ogre/bld/bin
./SampleBrowser &