In this instructable we will study how to gather all the necessary things and compile a real 3D-application...
...Who said GAMES?!
Hmm... Nobody?.. Let's continue then.
3D applications are necessary not only for gaming. Imagine You're using an MPU6050 gyro sensor and want to display its readins in a more robust form rather than just bare digits on the screen. Or You are controlling Your 3D-printer and want to display the model loaded by user. Or either You want a nice rotatable 3D-plot of newly acquired data.
However building a 3D application for the Orange PI is not the simpliest task on the world. Be prepared for a mini-marathon of 8 steps...
Of course, one can develop a 3D software barely by using low level Opengl commands, but it requires deep knowledge and tons of code. There exists another way: to use software, providing simple and human-readable programming interface - so called 3D engine. We will use Irrlicht here. Along with multiple of shortcomings it has one, but very strong advantage: IT IS EASY TO BE COMPILED. The other engines will get You sunk in "seek and destr...", srry - "seek and download" game for every other dependency. And You are lucky if You are able to win this game. In most cases You end up with a batch of corrupt links or incompatible versions.
As for the Irrlicht, here I will describe all things using Irrlicht 1.5.1 version. Why not the latest one? Well... I have already named the main advantage of the IrrLicht. Its time to name it's main disadvantage - it has a very unstable interface (API). From version to version they change function call conventions, and from time to time they change even the function names.I am, personnaly, tired from keeping up all my software with the newer and newer versions, so I decided to stop at some, maybe older, but fully functional and reliable version. For You it may be the other version of the IrrLicht. Generally the procedure of compilation is the same for any of them, except, maybe, some minor details.
Please note, that some releases of the Irrlicht are not easy to compile (have corrupt dependecies or incomplete sources). If Your are familiar with IrrLicht it is easy to add the absent things, to make necessary corrections and to compile. But if You are not familiar with Irrlicht and have faced some of its "hard to compile" releases, it may be better just to pick another release.
You will need:
- Orange PI, having been properly set up with Linux and video display. Keyboard and mouse for the Orange PI are also preferrable. How to set up a display You may read in my previous instructables - "Orange PI HowTo: Set it up to use with a 5" HDMI TFT LCD Display" (https://www.instructables.com/id/Orange-PI-HowTo-Set-It-Up-to-Use-With-a-5-HDMI-TFT/ ).
- Desktop PC running Windows and having working Internet connection. Further on I will assume that You also have a properly installed Code::Blocks IDE and x86Windows to ARMLinux cross compiler. How to get some You can read in "Orange PI HowTo: GPIO Led Blink application by cross compilation from Windows PC" (https://www.instructables.com/id/Orange-PI-HowTo-GPIO-Led-Blink-Application-by-Cros)
Step 1: Get Irrlicht Sourcecode
Go to https://sourceforge.net/projects/irrlicht/.../1.5.1/ and download irrlicht-SDK-1.5.1.zip archive. Unpack it to some folder on Your PC. Further on we will assume that this folder is named
Substitute it with Your own folder name if it differs.
Step 2: Get GL4ES Sourcecode
IrrLicht, like many other 3D accelerated software relies on the Opengl API and libraries that are presumably exist in the operation system of the target computer. As the advertisement says, Orange PI has a 3D accelerator onboard. (Inside the Allwinner's "System On Chip" to be more precise.) This 3D accelerator is named "Mali".
SUDDENLY: MALI IS NOT OPENGL COMAPTIBLE THING. It is compatible with GLES, but the GLES and OPENGL are just not the same.
Luckily there exist (API) interface wrappers, that can help us to accustom OPENGL software to using GLES for 3D acceleration.
Gl4es library is one of those wrappers and we will use it in our project.
GO to https://github.com/ptitSeb/gl4es/releases and download gl4es-1.0.4.zip archive.
Better to keep all things in the same place, so go to c:\irrlicht-1.5.1 and create c:\irrlicht-1.5.1\gl4es subfolder there.
Unpack the contents of gl4es sourcecode archive into the c:\irrlicht-1.5.1\gl4es folder (with preserving the subfolder tree structure of course).
Step 3: Get the Necessary Headers and Libraries From Your Orange PI
At the stage of compiling Your toolkit will need some headers (*.h files) and libraries absent in its initial distribuition. You will need X11 headers, libdl.so and some other files. You can get the needed files from Your Orange PI. However the amount of the necessary efforts depends seriously to the distribution of Linux, being installed on Your Orange PI. The distrubution has to contain all the needed files, has to contain a robust file manager in order to find and copy them easily and should have a fat32 partition on its flash card. The last requirement is optional (You can always use an USB flash memory dongle to transfer files) but it makes life easier.
From the known official distributions I recommend Debian 0.9.1 You can download it from http://www.orangepi.org/downloadresources/
Once You have Orange PI running the suitable version of Linux copy from there
- /usr/include/X11 - folder with all contents
You may want to copy the headers into
for the compiler to find them easily
Where _YOUR_COMPILER_INSTALLATION_FOLDER_ is obviously Your compiler installation folder (e.g. C:\SysGCC\Raspberry\).
Otherwise You may want not to disturb the compiler distribution.
Step 4: Compile Gl4es As Library
Now You should have irrlicht installed in c:\irrlicht-1.5.1 and gl4es unpacked into c:\irrlicht-1.5.1\gl4es
Start You Code::Blocks IDE
Select "Create new project" in the main Code::Blocks Window and choose "static library". In further dialogue window name Your project "gl4eslib" and select good place for it. A good choice is
But of course You can find a place that suits You better.
Click "Next" and in the following window choose "GNU GCC Compiler for ARM" Click "OK" to save Your project.
Then go to the "Management" window (the leftmost docked window, if You havent changed the interface layout), make sure that "Projects" tab of that window is selected (it usually is by default), seek for Workspace/gl4eslib in the project tree view, right click the "Sources" folder and choose "Add files recursively" from the context menu. Add there c:\irrlicht-1.5.1\gl4es\src\ folder of Your physical drive and agree with the default settings, the Code::Blocks offers.
Delete all main.c files from project.
Further on in the main dropdown menu navigate to Project->Build options... In the appeared window by default "Compiler settings" and "Compiler Flags" will be active. Set "Have gcc follow the 1999 ISO C language standard" checkbox to "on".
Go there to "defines" tab and add:
Then in the upper row of tabs select "Search directories" tab and make sure that "compiler" tab is selected in the row of tabs below. Click "add" and in the common dialogue window navigate to
Add it to the search paths.
Then use Build->rebuild menu item to build the gl4es as static library. There will be a lot of warnings in the building log, it is normal. But there should be no fatal errors. Case of success You will find a libgl4eslib.a file in Your gl4es project folder in the "bin\Debug" or "bin\Release" subfolder. This is Your gl4es library binary file. We will need it further on the stage of compiling IrrLicht itself
Step 5: Compile Jpeglib As Library
IrrLicht sourcecodes distribution does usually contain jpeglib in the
But the set of jpeglib files is in this folder is a bit excessive and containd more than needed for the flaweless compilation. When creating the project to compile jpeglib one needs to add the necessary files and exclude unnecessary ones. This is a bit tricky, so I better do it for You. Here is the project file "jpeglib.cbp"
Copy this file into Your
folder and open it with the Code::Blocks.
Select Build->Rebuild from the main dropdown menu and it will start the compilation.
The main drawback of presenting the ready project file is that it will work with Your Code::Blocks only if You have installed the cross-compiling tool as "GNU GCC Compiler for ARM". Otherwise You will need to correct the compiler settings using the settings that can be found in Project->Build Options or even in Project->Properties...
Step 6: Compile a Irrlicht As Static Library
Irrlicht distribution includes different project files that could be used for IrrLicht compilation from source codes. And a Code::Blocks project file is among them. However for some reason there's no success in activating Linux build target in this project. Therefore You are to create Your own project file.
Start Code::Blocks and in the title screen select "Create New Project" and further on choose "static library". In the next dialogue window You will be asked for the name of the project and for the placement of it. Better not to put Your project in source subfolder of the IrrLicht distribution.
Otherwise Code::Blocks may fall into infinite loop when You will try to add all files in this subfolder to the project.
The name of the project may be arbitrary, but let's assume that it is:
otherwise we will sink in tons of undefined names on further stages.
As usual select "GNU GCC Compiler for ARM" as the default compiler for the project and click Finish to finalize creation.
And don't forget remove main.c file from project.
When You've done with the project creation its time to add files to it.
You should already know how to add recursively files from a folder to a project (if not refer to step 4). Add recursively files from the folder:
Agree with the default file selection. After the files have been added exclude the following subfolders (the names given are as written in the project management window, and not as they are named on Your hard disk)
- irrstatic\ASM Sources
With the last two subfolders it may be a bit trickier to remove them. If Code::Blocks refuses to show the "remove files" menu item, just go a level deeper and make Your dark deeds there.
Further on go to Project->Build Options and add the next search directories for the compiler:
The last one is needed for the compiler to find the necessary opengl interface headers (like "gl.h", "glx.h" etc). If Your compiler has opengl headers in its sysroot folder You may not bother.
Then press Ctrl+F11 or just use a "rebuild" menu item. Finally You will obtain the irrlicht as static library in the
folder on Your hard disk (Since we are not going to use the debug features it is senseless to compile the project to debug target.)
The library file will be named as:
Note the "lib" preffix to the left of the name of the project and the ".a" extension.
Step 7: Compile a 3d Program Sample With Irrlicht
Now we have all the needed components:
- libirrstatic.a - Irrlicht as static library we have just built
- libjpeglib.a - jpeg library we have built at the stage 5
- libgl4eslib.a - gl4es library we have built at the stage 4
- libX11.so - taken from our Orange PI
- libXxf86vm.so - taken from our Orange PI
- libdl.so - taken from our Orange PI
To compile a 3D program we need these 6 files and the files contained in
The other stuff is no longer needed unless You plan to rebuild it once again.
Let's test the functionality of the collected stuff. (If You have just compiled the IrrLicht and Your computer is not very strong it may be better to restart Your computer at this point). Start the Code::Blocks and select "new project" on its main screen. Select "console application" and choose "c++" as its default language. Give the project a name and place it somewhere on Your hard disk.
As usual the name and place may be any of Your choice, but for certainty we will think that the project is named "test" and placed in
Then select "GNU GCC Compiler for ARM" as the default compiler for the project. Finish the creation of the project.
Now exclude the auto-created main.cpp from the project and delete it from th hard disk.
Then go to "c:\irrlicht-1.5.1\examples" and pick an example to compile. For the first try it may be better to compile the most simple example - the "Hello World" but I will use "Special FX" example for further explanations.
Pick the main.cpp file from the "c:\irrlicht-1.5.1\examples\08.SpecialFX" folder and copy it to our "c:\irrlicht-1.5.1\test" folder. Overwrite if needed.
In the folder "c:\irrlicht-1.5.1\test" make a subfolder and name it "libs".
Find and copy our 6 essential files into the "c:\irrlicht-1.5.1\test\libs". So that You should have:
ready for further use.
DO NOT TRY TO PUT THE LIBRARIES IN THE SAME FOLDER WITH THE PROJECT. For some reasons if the library is situated in the same folder with the project being compiled the Code::Blocks generates broken path.
Then return to the Code::Blocks and navigate to Project->Build Options of the main Code::Blocks menu. Go to the "Search directories" tab and add "c:\irrlicht-1.5.1\include" as the compiler search directory.
In the same window (Project->Build options) go to the "Linker settings" and add our 6 essential files (libirrstatic.a, libjpeglib.a, libgl4eslib.a, libX11.so, libXxf86vm.so, libdl.so) to link with.
Finally select "Release" as the build target and press Ctrl+F11 or choose Build->Rebuild in the main menu.
After some time You will have the
file. And it is Your first 3D example program compiled for Orange PI.
Step 8: Copy the Executable to Your Orange Pi and Run It
Copy c:\irrlicht-1.5.1\test\bin\Release\test.exe file to some folder of Your Orange PI flash memory card. Note that if You have correctified the names of .so files when copied them from the orange PI the Linux will be unable to find the necessary shared objects (shared libraries) and You will need to copy them together with Your project.
It may be better to copy all 4 files (test.exe, libX11.so, libXxf86vm.so and libdl.so) together in any case - for not to think each time whether You need them all or not.
For the sample to be functional on Your Orange PI You will need to copy one more thing: a "media" folder from the IrrLicht distribution. Copy the contents of Your c:\irrlicht-1.5.1\media folder to a folder on Your Orange PI so that the "media" folder be placed by two level higher in the directory structure than the test.exe is placed. It is needed for the code to be able to find the correspondent media files (3d-models and pictures).
Alternatively You might change the paths for the media files in the c++ code of the example just before compiling it.
Step 9: As Usual I've Uploaded Several Ready to Use Packs
irrCompile.zip - a ready to use kit for cross compile IrrLicht 1.5.1 to OrangePI Linux. How to use:
- go to ..\irrlicht-1.5.1\source\Irrlicht\jpeglib\; start jpeglib.cbp with Code::Blocks and compile;
- go to ..\irrlicht-1.5.1\gl4es\src\tests\gl4eslib\; open gl4eslib.cbp with Code::Blocks and compile;
- go to ..\irrlicht-1.5.1\irrstatic\; open irrstatic.cbp with Code::Blocks and compile.
irrHW.zip - a ready to use kit for cross compile IrrLicht's Hello World sample contains irrHW\include folder with irrlicht include files needed for compilation, libirrstatic.a and other libraries needed for compilation media folder with files needed to run the example.
How to use:
- go to ...\irrHW\examples\01_HelloWorld and start 01_HelloWorld.cbp with Code::Blocks, Compile, copy to Orange PI as described above and run the example there.
irrExamples.zip - a set of IrrLicht examples precompiled for Orange PI How to use: Unpack to Orange PI flash card with preserwing directory structure. Run the unpacked on the Orange PI under Linux.
Step 10: NOTES
- The "Orange PI", "Code::Blocks", "Windows", "Linux", "Sunxi-Tools", "Allwinner", "IrrLicht", etc... are the correspondent trademarks of their respective owners.