Return to the tutorials list.

17 - Bonzai Engine on Android

Bonzai Engine is available in Android with the same api and feature available on other platforms.
Bonzai Engine jar is available for OpenGL Es 1.1 and OpenGL Es 2.0 (recommended). The binary are available in the regular distribution in /bin/android.

The api is identical between android and desktop, so most of the development can be done on desktop.
One exemple is the viewer tool which runs similarly on android:
Model Viewer

See Gallery for the full video.

To keep good performance on android devices, all assets must exclusively be convert into Bonzai Engine binary formats which has been optimized for fast loading and rendering on android devices:
 * jmf (recommended) or jaf for models
 * tex or dds for textures
 * jaf for animation (if separate from model)
Using other format will result to slower loading and so therefore less attractive use experience.
For more information about optimization, please read the associated tutorial.

Let's begin with a standalone tutorial which creates an activity and initialize everything.

The function registerStreamCallback has the purpose of accessing files from apk assets. The function registerLog is usefull to redirect the API logging to the Android DDMS log (and ide DDMS plugin).
Except that, everything you'll see is similar to what you should already know:



It can be usefull to develop on desktop which is just way faster to develop, test and debug compared to an android device (or emulated).

Let's see how this can be done. The first source is the 'main' class for android

the next source is main class for desktop:

both uses the same code for loading and rendering:


Redirect back key as ESC button
Activity can be overrided to catch back key touch. The snippet code below catch back key and dispath a key event which will be triggered in usual KeyListener.
This code block is used in our viewer and editor tool.


Automatic UI scaling to keep same size
This next method is intended to be called in Application.onCreate before any UI initialization. It initialize UI scaling to have same UI size independently to device screen resolution.
This code block is also used in our viewer and editor tool.