Pro Android Games

Vladimir Silva

Mentioned 5

Do you remember landmark games like Wolfenstein 3D, Doom, and Asteroids? Well, here’s an exciting opportunity to build and/or port these games to one of the hottest mobile and netbooks platforms today: Google’s Android. Pro Android Games teaches you how to build cool games like Space Blaster and the classic Asteroids from scratch on the latest Android platform. This book also shows you how to port other classic freeware/shareware games like Doom and Wolfenstein 3D from C using the Java Native Interface (JNI) for Android. This book is all about a unique perspective in Android game development: a well-balanced, powerful combination of pure Java and hybrid game development, mixing Java and C. By combining the elegant object-oriented features of Java and the raw power of C, there is no limit to the types of games that you can build for the platform. With actionable real-world source code in hand, this book allows you to dive right into games development on Android. You’ll definitely have fun, and perhaps you’ll even make some money. Enjoy! What you’ll learn How to write/port advanced 3D games for any Android device. How to setup a Linux system for hybrid game compilation. How to combine Java and C code in an elegant manner by building a simple Java application on top of a native library. How to tackle pure Java gaming with two practical games: Space Blaster and the arcade classic Asteroids. How to mix OpenGL API calls in Java and C for high performance 3D graphics using the 3D cubes sample by Google. How to bring two of the greatest PC 3D shooters to the Android platform: Wolfenstein 3D and Doom using Java and C. Who this book is for This book is for Google Android developers interested in game application development in Java or porting existing C-based games via JNI into Android and developing/deploying from there. It is targeted to developers who already know such basics of Android development as activity, view, and layout. Additionally, it assumes that you are a seasoned game developer in Java and C, and have a basic knowledge of Linux and Shell Scripting. Table of Contents Welcome to Android Gaming Compiling Native Code in Android Building a Java Game from Scratch Java Games Continued: Fun with Polygons Hybrid 3D Graphics with OpenGL and JNI 3D Shooters Episode I: Wolfenstein 3D for Android 3D Shooters Episode II: Doom for Android

More on

Mentioned in questions and answers.

I've just started learning OpenGL ES on android (using this book) and came across an issue of adopting source code from chapter 5 to existing methods of using jni in android (actually, it also concerns simply running a native GL app). I'm trying to compile the native code to get the .so lib and use it further in .apk archive. But compilation is not possible if certain libs are not present (which are GLES/gl.h, EGL/egl.h, GLES/gl.h, GLES/glext.h).

So the question is how do I install those libs (AFAIU, OpenGL ES and EGL installation) and compile the most trivial native code? (tutorials are highly admired).

Thanks in advance.

EDIT: I've tried the glbuffer example as was suggested (slightly changed .mk file), but still no success. Compiler gives me the same result as before:


Compile thumb: egl <= cube.c

/path/jni/cube.c:5:21: error: GLES/gl.h: No such file or directory // same message for glbuffer when gl.h is being included

Here is the cube.c code:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#include <GLES/gl.h>

#define FIXED_ONE 0x10000
#define one 1.0f

typedef unsigned char byte;

extern void jni_printf(char *format, ...);

// Cube static 
GLfloat vertices[24] = {        -one, -one, -one,       one, -one,
-one,       one,  one, -one,        -one,  one, -one,       -one, -one,  one,       one, -one,  one,        one,  one,  one,        -one,  one,  one, };

static GLfloat colors[] = {         0,    0, 0,  one,       one,    0,    0,  one,      one,  one,    0,  one,      0,  one,    0> ,  one,      0,    0,  one,  one,        one, 0,  one,  one,         one,  one,  one,  one,      0,  one,  one,  one, };

static byte indices[] = {       0, 4, 5,   0, 5, 1,         1, 5, 6,    1, 6, 2,        2, 6, 7,    2, 7, 3,        3, 7, 4,    3, 4, 0,        4, 7, 6,    4, 6, 5,        3, 0, 1,   3, 1, 2 };

void Cube_draw() {
glVertexPointer(3, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_FLOAT, 0 , colors);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices); }

It's awfully trivial and not working, yet.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := egl
LOCAL_SRC_FILES := cube.c cuberenderer.c


Those libraries are provided by Android itself. However, setting up your project to find them and compile your JNI (native) code correctly can be daunting.

I recommend using glbuffer as a starting project, as it will provide you with a GLSurfaceView to draw on and set you up with the proper Android libraries.

The details of linking to the Android libraries are contained in jni/ inside that project if you'd like to give it a shot yourself from scratch.

Edit - apparently glbuffer is missing jni/ Create it and put this inside:

APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-8

Then the ndk will know to look inside the android-8 platform for your includes. You can change this to other versions as needed.

I am trying to find some very basic tutorials like how to draw a line, how to draw a triangle, how to draw a rectangle etc using OpenGLES in android. All the tutorials I found are in Java but I am looking for C++ based samples. I'll be very thankful if someone can point me to such tutorials.


I am creating activity and renderer in Java but I want to implement/redirect methods like OnDrawFrame, OnSurfaceChanged and OnSurfaceCreated in/to C++.

I would advise to first learn OpenGL (2.0+) on the desktop and then move to OpenGL|ES. As a beginner you are bound to make mistakes and it will be easier to find, fix and learn from them as well the theory and requirements of 3D rendering. When you have a firm grasp you could make the jump instantly into OGL|ES with just the reference pages at hand.

For a crash course though, this book and that have proven quite useful.

Actually this question is asked earlier.. OpenGL on Android using C++ only may be its useful for you.. But the correct approach is first learn opengl because opengles is like a subset of opengl. here a link for a good book

Are there any e-books out there on the topic of OpenGL in Android?

You haven't said how experienced you are with OpenGL and/or Android in general, but I'll assume that you are familiar with the basics.

In that case, the two books in this series both have significant coverage of OpenGL, which you can see by looking inside at their table of contents:

Those, together with a reference book on standard OpenGL ES 2.0 should be all you need for a long, long time.

Can anyone suggest me the best place to start with for learning Open GL ES .... some good tutorial site or some pdf .....

Getting started with OpenGL... in Android

Pro Android Games

Beginning Android Games

Also check Related Links regarding to your question, which are bottom right of your question.

I'm planning to develop a simple tic-tac-toe 3D game for android as a starting point (practical task to learn and do something useful), but devguid seems to be more of a reference than something with what I can get my hands on particular task. Can someone advice what should be investigated? (or maybe I'm searching for it incorrectly)

EDIT: I'm also considering other options on learning android development. (Though, the "practice while learning" approach is preferred).


My purpose: learn how to develop apps for android && create an app, which is fun and can be placed on android market

My initial "data": strong java + java ee, basic C/C++, willing to learn

Means to achieve purpose: devguide is more of a reference, and I need a solid start with lots of explanations. Need an advice here.

Try out several tutorials here, especially testing ones. Get your hands on Pro Android Games with reading devguide when some part of android development is unknown.

This will result in a rapid development (with a zero level starting point) and small learning curve of basic + in deep android development.