Osg Android
Posted : admin On 1/26/2022Project website for OpenSceneGraph. The OpenSceneGraph has range of dependencies, listed at the bottom of this page, most of which are optional and only required if you want to load a. 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. Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google. OSG offers drills, taps, end mills and indexable cutting for a wide variety of applications.
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+
- g++
- 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)
g++
Download Eclipse and extract it.
$HOME/Android/eclipse/
Download Android SDK and extract it into
$HOME/Android/android-sdk-linux/
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
$HOME/android-sdks/
Extract Android NDK to
$HOME/Android/android-ndk-r8b/
(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
$HOME/Android/OpenSceneGraph-3.0.1/
Download the 3rd party dependencies (link) and extract it to
$HOME/Android/OpenSceneGraph-3.0.1/3rdparty/
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:
export ANDROID_NDK=$HOME/Android/android-ndk-r7b
export ANDROID_SDK=$HOME/android-sdks
Create two folders:
$HOME/Android/OpenSceneGraph-3.0.1/build

$HOME/Android/OpenSceneGraph-3.0.1/osginstall
Open a terminal and change directory to
$HOME/Android/OpenSceneGraph-3.0.1/build
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):
Osg Android
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):
make
Install libraries and headers into $HOME/Android/OpenSceneGraph-3.0.1/osginstall into the folder obj, lib, and include, by typing:
make install
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
$HOME/Android/OpenSceneGraph-3.0.1/examples
to your Eclipse workspace
$HOME/workspace/osgAndroidExampleGLES1
Copy the three folders under $HOME/Android/OpenSceneGraph-3.0.1/osginstall, obj, lib, and include to your project folder:
$HOME/workspace/osgAndroidExampleGLES1
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:
Osg For Android
Type
$ANDROID_NDK/ndk-build
Osgearth Api
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.
Osgearth Android
* this tutorial was adapted from this link.