To properly setup an environment for Android development using OpenSceneGraph, we need the following hardware and software:
- Android Tablet – Acer Iconia Tab A510 (Tegra 3 Processor)
- OpenSceneGraph – 3.0.1
- cmake: 2.8+
- Eclipse Indigo
- Ubuntu 11.04 or Ubuntu 11.10
- Android SDK
- Android NDK
Setup a working Android development environment in Ubuntu:
Open Synaptic Package Manager.
Install package openjdk-6-jdk.
Install the following two packages using either Synaptic or apt-get:
cmake (sudo apt-get install cmake)
Download Eclipse and extract it.
Download Android SDK and extract it into
Install ADT-Plugin into Eclipse.
Start Eclipse -> Help -> Install New Software -> in the field ‘Work with:’, fill in “https://dl-ssl.google.com/android/eclipse/”, then press Enter -> check “Developer Tools” -> press Next till everything is installed.
After restarting Eclipse: Window -> Android SDK Manager. Install AT Least Android 2.2 (API 8).(I installed ALL the Android API versions from API 8 to API 15). I installed these APIs to
Extract Android NDK to
(ndk-r7b and ndk-r7b have been proven to work with OSG)
After everything has been copied to the appropriate directories, we now have a working environment for Android development.
Installing OpenSceneGraph 3.0.1 for Android with OpenGE ES 1.x
Download OpenSceneGraph-3.0.1 (link) and extract it to
Download the 3rd party dependencies (link) and extract it to
Add environment variables so that cmake will find the right dependencies, open ~/.bashrc and add the following lines at the end of the file and save it:
Create two folders:
Open a terminal and change directory to
Type in or copy the following command in the terminal and press Enter (the flag -DJ=4 is to specify we have a quad-core processor):
cmake .. -DOSG_BUILD_PLATFORM_ANDROID=ON -DDYNAMIC_OPENTHREADS=OFF -DDYNAMIC_OPENSCENEGRAPH=OFF -DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF -DOSG_GL_MATRICES_AVAILABLE=ON -DOSG_GL_VERTEX_FUNCS_AVAILABLE=ON -DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=ON -DOSG_GL_FIXED_FUNCTION_AVAILABLE=ON -DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF -DOSG_GL1_AVAILABLE=OFF -DOSG_GL2_AVAILABLE=OFF -DOSG_GL3_AVAILABLE=OFF -DOSG_GLES1_AVAILABLE=ON -DOSG_GLES2_AVAILABLE=OFF -DJ=4 -DCMAKE_INSTALL_PREFIX=$HOME/Android/OpenSceneGraph-3.0.1/osginstall
After that, we build it (this step usually takes quite a while):
Install libraries and headers into $HOME/Android/OpenSceneGraph-3.0.1/osginstall into the folder obj, lib, and include, by typing:
After this, we have a working environment for developing Android application using OpenSceneGraph.
An Example: creating and build a project
Copy the folder osgAndroidExampleGLES1 from
to your Eclipse workspace
Copy the three folders under $HOME/Android/OpenSceneGraph-3.0.1/osginstall, obj, lib, and include to your project folder:
Start Eclipse -> New -> Project -> Android Project, choose “Create project from existing source” and set the location to $HOME/workspace/osgAndroidExampleGLES1 -> Project Name is “osgAndroidExampleGLES1”, then Next -> build target should be Android 2.2 (API 8) or higher.
In Eclipse project browser, expand the folder jni and open Android.mk in text editor, make the following two changes and save it:
Now the native code has been built for the Android OSG Viewer, we can go back to Eclipse and build the project from there.
A video demonstrating the osgViewer application on the Acer tablet.
* this tutorial was adapted from this link.