Programming 3D games on Android with Irrlicht and Bullet (Part 1)
Just got a new Android phone (a Samsung Vibrant) a month ago, so after flashing a new ROM and installing a bunch of applications, what would I want to do with the new phone? Well, I’d like to know if the phone is fast enough to play 3D games. From the hardware configuration point of view, it is better equipped than my desktop computer in the 1990s, and since my desktop computer at the time had no problem with 3D games, I would expect it to be fast enough to do the same.
At first, I was considering downloading a 3D game from the market, but 3D games for Android are still rare, then why don’t I just create a 3D demo game myself?
After looking around which 3D game engines are available for the Android platform, I just settled down with Irrlicht. This is an open source C++ graphic engine, and not really a game engine per se, but it should have enough features to create my demo 3D application. And I like to have realistic physics in my game, so what could be better than the Bullet Physics library? This is the best known open source physics library, also developed in C++. The two libraries together would be an interesting combination.
Although Irrlicht was developed for desktop computers, but luckily enough, someone has already ported Irrlicht to the Android platform, which requires a special device driver for the graphic engine. And guess what? Someone has also created a Bullet wrapper for the Irrlicht engine. All of them in C++, and open source. All we need to do now to pull all these codes together to build a shared library for Android.
In this part, I’ll just describe what needs to compile all the codes for Android. Since we will compile C/C++ codes, you’ll need to download the Android native development kit. Please refer to the documentation on how to install.
We create an Android project, and add a jni folder. Then we put all the C/C++ source codes under the jni folder. I created three sub-folders:
- Bullet: All the Bullet Physics source codes. Actually, we only need the Collision, Dynamics, Soft Body and Linear Math libraries.
- Irrlicht: The Irrlicht 3D graphic engine source codes. This is the Android port of the engine.
- irrBullet: This is the Bullet wrapper for Irrlicht engine, which makes it easier to write your programs.
After, all we need to do is to create an Android.mk file, which is quite simple, really. You can read the makefile to see how it is structured. Basically, we just tell the Android NDK build tools that we want to build all the source codes for the Arm platform, and we want to link with the OpenGL ES library, to create a shared library called libirrlichtbullet.so. That’s about it.
However, there’s one minor thing to note though. Android does not really support C++ standard template library, but the irrBullet library made use of it. Therefore, in the jni folder, we need to add an Application.mk file, which contains the following line:
APP_STL := stlport_static
And that’s it. Now, you can run ndk-build to build the shared library. If you have a slow computer, it would take a while. If everything is alright, you should have a shared library in the folder libs/armeabi/. That shared library contains the Bullet Physics, Irrlicht and the irrBullet wrapper libraries. You can now create your 3D games for Android with it. In the next part, we will write a small demo program using this library.
You can download all the source codes and pre-built library here.
Thanks for the pre-built shared library, and all the work of putting all these together. I was trying to build them myself, and got into all kinds of problems.
Thank you.
Thanks for putting all these libraries together. I was trying to do the same thing yesterday, good thing I did a search first
Thanks for the library. I’m too lazy to put them together and to build it myself, besides, my computer is kinda slow, so…
That’s cool. Would you port this to iPhone, eventually? Or do you know if anyone has done it already?
Thanks a lot for sharing.
@Andrew,
I’m not sure if anyone has already ported Irrlicht and Bullet to iPhone, I’d guess this is already done.
As for me to port it to iPhone, this is probably not going to happen any time soon. Firstly, I have no Apple computer and iPhone. Secondly, I have never used an Apple computer or iPhone in my life. Thirdly, I have no intention to buy an Apple computer any time soon. So there…
Great work, thanks for putting all these together.
John
Thanks for the library.
But source codes and pre-built library is broken.
Please upload it again.
Thanks a lot for sharing.
Hi Joon,
What platform are you trying to run on? The library is built for the Arm platform (CPU used in most (?) Android phones). If you try to used the pre-built library on an Android run inside a virtual machine (e.g. VirtualBox), which is running on a desktop machine (which most likely, is an x86 platform), it will not work.
To build the source code, you need to have the Android NDK installed.
Please let me know what kind of problems you have seen.
Thanks for putting all these libraries together. I was trying to do the same thing by your , but your tar.gz file is broken.
Please upload it again. thanks
Actually it’s true, the file is broken.
i’d realy appriciate a new upload as well.
thx and greate post
I don’t know what happened, it must be that the file is chopped before download is finished. I just downloaded it, and it’s decompressed ok. Other people have downloaded previously without problem too.
Anyway, I just uploaded a new file. It’s smaller, because I cleaned up all the object files. All the source codes are there, you would have to build them yourself.
For those who had problem downloading, please try again. Sorry for the inconvenience.
Hello,
I tried to build your project but got “multiple definition of `GL_BGRA’” error and bunch of “undefined reference to `glFogf’”, etc…
Would you help, please?
Sorry, I’ve resolved it. Commented out #define _IRR_COMPILE_WITH_OGLES2_
in IrrCompileConfig.h
Hi,
Thanks for all the work. I’m trying to compile this with ndk-r7 on android-9 with GLES2, but I’m having a terrible time at it. Would you happen to have an updated project? If not, would you be willing to help me out if I post (or upload) what I have?
Regards,
Joe
I forgot to mention that I can’t compile the project as is either with ndk-r7.
Thanks
Nevermind, I downloaded irrlicht android from git and all is fine now. Thanks for the awesome tutorial.
i downloaded the sourcefile, but i can’t compile it with ndkr5, ndkr6 either ndkr7 in XP or Win7. it always comment:
make: execvp: /cygdrive/d/CTNDK6/toolchains/arm-linux-androideabi-4.4.3/prebuil t/windows/bin/arm-linux-androideabi-g++: Argument list too long
how can i solve this problem?