Click here to Skip to main content
13,595,081 members
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 6 Nov 2012
Licenced CPOL

One-Touch Casual 3D Game Based on OpenGL ES 2.0 3D Engine with Lua, Bullet, and Vorbis Support

, 8 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Android-x86 native game-engine - without JNI

1. Link to Android x86 Projects Archive

2. Link to CasualGame.apk for Android x86

3. Link to CasualGame.apk for ARM


This article is part of our Android at Play: Android Game App Contest and has different requirements and requires less strict guidelines.


This is a simple game that can be played in the simulator as well as on the device. Can you beat my x86 simulator best time of 19 secs? :)

You need to touch the area near the bottom of the space-craft to make it rise. Once air-borne, touch to the left of the space-craft to make it go to the right. Experiment with the control till you get the knack of it. Beat my time!!!

For those experienced in Android NDK development, the brief detail about my dev setup and procedure should be sufficient to get the code built.

For those new to Android NDK development, you will need to do go through some basic Android NDK tutorials on the net and on CodeProject. :)

I eagerly look forward to any questions or suggestions you may have with regards to this code base and even its dev setup (as it is a tricky thing in Android NDK development).

Inspiration and Motivation

I have based my work off the Apache 2.0 licensed 'gameplay' engine for BB10 by RIM.

While the game itself appears simple, it covers key concepts like 3D physics using Bullet, importing assets from Maya (or Max), and dynamic light calculations.

Equally important, I would like to draw attention to the poweful engine used to create this game.

A large part of my effort was directed at porting, modifying and enhancing this game-engine for use on the Android x86 platform.

Based on my professional experience, findings, and learnings in cross-platform smartphone game development, I can confidently state that this framework strikes the best balance as a lean yet feature-rich collection of open-source technologies for Android x86 game development.

Important: This code base comprises of only C and C++. It has no Java code. It relies on the Native Activity feature of Android.

Game Implementation Details

The basic goal of this game is to pilot a space ship through a fixed distance in the shortest time.

The art assets are modeled in Maya. They are kept simple. The roof and floor meshes are repeated to create a long tunnel. A simple texture is used for the tunnel. Dynamic lighting is used to create interest in the scene.

Controls (algo)

1. The player touches the screen near the ship to activate the throttle.

2. The distance between the finger and the center of the ship determines the throtle magniture.

3. The angle between the finger and the horizontal axis of the ship determine the thrust angle.

4. If no input is applied, the ship drops as a result of gravity.

5. For adding interest, the ship does spins, and adjust exhaust glow based on throttle magnitude.

6. The sound pitch too is proprtional to the throttle magnitude.

The 3D models, fonts and sounds for the game are initially exported as FBX, ttf and wav. However, they are encoded to the gpb format via the gameplay-encoder for use in the engine.

Font loading

Font *_font = Font::create( "res/airstrip.gpb" ); 

Scene and Model loading

/ / contains spaceship, roof, ground etc..
Bundle *bundle = Bundle::create( "res/spaceship.gpb" ); 
_scene = bundle->loadScene(); 

/ / get a handle to the spaceship
Node *_shipNode = _scene->findNode( "pSpaceShip" ); 

SAFE_RELEASE( bundle );  

Using shaders from the shader library

material = _shipNode->getModel()->setMaterial( "res/shaders/colored,vert", " res/shaders/colored.frag", SPECULAR, 0 );  

Accessing the active camera in the scene

_scene->getActiveCamera()->setAspectRatio( 1.5 );

Camera movemement

void SpaceshipGame::updateCamera()
    if (_finished)        

    / / Keep the camera focused on the ship    
    const Vector3& cameraPos = _cameraNode->getTranslation();    
    const Vector3& shipPos = _shipGroupNode->getTranslation();    
    float diff = cameraPos.x - shipPos.x;    
    if (diff > CAMERA_RANGE_BACK)    
       _cameraNode->translateX(-(diff - CAMERA_RANGE_BACK));    
    else if (diff < -CAMERA_RANGE_FRONT)    
        _cameraNode->translateX(-(diff + CAMERA_RANGE_FRONT));   

Game rendering

void SpaceshipGame::render( float elapsedTime ) 
    clear( CLEAR_COLOR_DEPTH, Vector4::zero(), 1.0, 0 );
     / / for opaque drawing
    _scene->visit( this, &SpaceshipGame::drawScene, ( void * ) 0 );
     / / for transparent drawing    
    _scene->visit( this, &SpaceshipGame::drawScene, ( void * ) 1 ); 
    _font->drawText( "Click to Play again", getWidth() / 2 - 175, getHeight() / 2 - 40, Vector4::one(), _font->getSize() ); 

Handling game-over

void SpaceshipGame::resetGame()
    _time = 0;
    _finished = false;
    _velocity.set(0, 0);


The biggest challenge in using the stock engine on platforms other than the BB10 is that all the external dependencies of the engine are provided as prebuilt libraries. The problem only gets worse for Android x86 as it isn't even a supported platform for the stock engine.

This was the primary roadblock that I faced while working on this game. I removed the dependencies on the prebuilt libraries and replaced them by the actual sources of the libraries. The library sources that I have added (and statically linked) to the engine include,

  1. Lua 5.2, for scripting. (Refer here for compiling Lua on Android -

  2. Bullet 2.7

  3. OpenAL - This was convoluted due to this project being a NativeActivity. Was made to think in the right direciton after reading this

  4. PNG

  5. Zlib

  6. Vorbis

Dev Setup

  1. Win7 x64 Host, Fedora 16 Guest. i.e. a Linux dev environment

  2. Android SDK r2.0.0.3, NDK r8b, API 15 (x86)

  3. Eclipse 3.7 (with ADT, CDT and Sequoyah)

  4. DS5 ARM Debugger Community Edition (the best for Android Native Activity debugging)

  5. Ant (for asset packing only)

  6. Maya 2013

  7. AVD (API 15 with GPU emulation enabled)

Steps to follow
  1. On unzipping the archive, you will get 2 Android NDK projects and an external-deps folder. These are the bare essentials needed for building this game, and they include all the modifications mentioned above.
    1. gameplay, this is the game engine
    2. CasualGame, this is the game
    Do check the and files. The original files are renamed to and respectively.
  2. From within Eclipse, import both projects as 'Existing Projects into Workspace' This will preserve all settings necessary to build these projects correctly. Remember to import from within the android sub-folder, else Eclipse won't recognize these projects as Android NDK projects.
  3. First build the gameplay project. This will build the engine as a static lib, libgameplay.a in the gameplay/android/obj/local/x86 folder.
  4. Next, build the CasualGame project. This will build the game as a shared lib,
  5. Now we have built the native parts of our code. Next we need to add the game assets to the apk. This is done from the command line via ant.
  6. Navigate to the android sub-folder of the CasualGame project, and type android update project -t 1 -p . -s
  7. Next type, ant debug install. This will generate the apk containing our NDK code and insert into it the assets for the game. Thus we end up with CasualGame.apk.
  8. Now come back to Eclipse and run/debug the project as a normal Android NDK application.

Points of Interest

Successfully created a game and ported a lean, feature-rich game-engine for use on the Android x86 platform. Yay!! Yay!! Yay!!

Do let me know if you run into any roadblocks. Will help out how I can. :)


v1.0 - gameplay for Android x86.

v1.1 (in progress) - Optimizing the 3D RacerDemo based on this framework. Adding 2D texture packing and animation tools.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Mihai MOGA14-Dec-12 5:13
memberMihai MOGA14-Dec-12 5:13 
QuestionRoof and Floor mesh Pin
darkblue.3d28-Nov-12 6:33
memberdarkblue.3d28-Nov-12 6:33 
QuestionNeedless! Pin
pip0108-Nov-12 23:30
memberpip0108-Nov-12 23:30 
AnswerNeedless?? Very much needed :) Pin
TG1e9-Nov-12 2:46
memberTG1e9-Nov-12 2:46 
GeneralRe: Needless?? Very much needed :) Pin
pip0109-Nov-12 3:39
memberpip0109-Nov-12 3:39 
GeneralRe: Needless?? Very much needed :) Pin
TG1e9-Nov-12 3:51
memberTG1e9-Nov-12 3:51 
GeneralRe: Needless?? Very much needed :) Pin
pip0109-Nov-12 4:14
memberpip0109-Nov-12 4:14 
GeneralRe: Needless?? Very much needed :) Pin
TG1e9-Nov-12 4:33
memberTG1e9-Nov-12 4:33 
GeneralRe: Needless?? Very much needed :) Pin
pip0109-Nov-12 5:15
memberpip0109-Nov-12 5:15 
SuggestionProject ZeroBrane for gameplay?? Pin
TG1e9-Nov-12 5:24
memberTG1e9-Nov-12 5:24 
SuggestionCouldn't resist this :P Pin
TG1e8-Nov-12 6:45
memberTG1e8-Nov-12 6:45 
QuestionOpinion Article Pin
Sr.WhiteSkull8-Nov-12 4:06
memberSr.WhiteSkull8-Nov-12 4:06 
AnswerRe: Opinion Article Pin
TG1e8-Nov-12 5:09
memberTG1e8-Nov-12 5:09 
AnswerRe: Opinion Article Pin
Sr.WhiteSkull8-Nov-12 6:56
memberSr.WhiteSkull8-Nov-12 6:56 
NewsLink to CasualGame ARM apk for Android 4.0.3 Pin
TG1e8-Nov-12 3:39
memberTG1e8-Nov-12 3:39 
QuestionBug Pin
Oleg Bulychov7-Nov-12 23:18
memberOleg Bulychov7-Nov-12 23:18 
AnswerRe: Bug Pin
TG1e7-Nov-12 23:26
memberTG1e7-Nov-12 23:26 
SuggestionA thought Pin
Slacker0076-Nov-12 23:05
memberSlacker0076-Nov-12 23:05 
GeneralRe: A thought Pin
TG1e7-Nov-12 1:10
memberTG1e7-Nov-12 1:10 
GeneralRe: A thought Pin
TG1e8-Nov-12 4:15
memberTG1e8-Nov-12 4:15 
QuestionRe: A thought Pin
Slacker0078-Nov-12 4:28
memberSlacker0078-Nov-12 4:28 
AnswerRe: A thought Pin
TG1e8-Nov-12 5:07
memberTG1e8-Nov-12 5:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180621.3 | Last Updated 8 Nov 2012
Article Copyright 2012 by TG1e
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid