Chapter 1
Beginning Android 3D
Game Development Part-1
Let’s Meet the Android
Android
mobile phones dominate the mobile smartphone market, surpassing even Apple’s
iPhone.
There
are hundreds of millions of mobile phones using the Android operating system in
over
190
countries around the world. Every day, a million new users begin using their
Android phones to
surf
the Web, to e-mail friends, and to download apps and games. In fact, in the
Google Play Store
alone,
there are 1.5 billion downloads per month of Android games and applications. If
you include
other
web sites that offer Android games and apps for sale, such as Amazon App store
for Android,
then
the number is even higher.
In
this chapter, you will learn about the Android Software Development Kit (SDK).
You will learn how
to
set up the Android development environment. You will also learn about the major
components
of
this environment, such as Eclipse. We then go through the creation and
deployment of a simple
“Hello
World” program for Android, to both a virtual Android emulator program and also
a real
Android device.
Overview of Android
The Android operating system is a widely used operating system
available on mobile phones and
tablets. It is even used on a video game console called the Ouya.
Android phones range from
expensive phones that require a contract to inexpensive prepaid
phones that do not require any
contract. Developing programs for the Android platform does not
require any developer’s fees,
unlike Apple mobile devices, which require yearly fees in order to
even be able to run your program
on their devices. A good working prepaid no-contract Android phone
that can develop 3D games
using
OpenGL ES 2.0 can be bought on Amazon.com for as little as $75–$100 with free shipping.
Overview of the Android
SDK
This
section discusses the Android SDK. Development system requirements and
important individual
pieces
of the SDK, such as the SDK Manager, Android Virtual Device Manager, and the
actual
Android emulator
will be covered.
Android Software Development
Kit (SDK) Requirements
Android development can be done on a Windows PC, Mac OS machine,
or a Linux machine. The exact
operating system requirements are as follows:
Operating Systems:
Windows XP (32-bit), Vista (32- or 64-bit), or
Windows 7 (32- or 64-bit)
Mac OS X 10.5.8 or later (x86 only)
Linux (tested on Ubuntu Linux, Lucid Lynx)
GNU C Library (glibc) 2.7 or later is
required.
On Ubuntu Linux, version 8.04 or later is
required.
64-bit distributions must be capable of
running 32-bit applications.
Developing Android programs also requires installation of the Java
Development Kit. Java Development
Kit requirements are JDK 6 or later and are located at www.oracle.com/technetwork/java/javase/
downloads/index.html.
If you are using a Mac, then Java may already be installed.
The Eclipse IDE program modified with the Android Development
Tools (ADT) plug-in forms the basis
for the Android development environment. The requirements for
Eclipse are as follows:
Eclipse 3.6.2 (Helios) or greater located at http://eclipse.org
Eclipse JDT plug-in (included in most Eclipse
IDE packages)
Android Development Tools (ADT) plug-in for
Eclipse located at
http://developer.android.com/tools/sdk/eclipse-adt.html
Notes Eclipse 3.5 (Galileo)
is no longer supported with the latest version of ADT. For the latest
information
on Android development tools, go to http://developer.android.com/tools/index.html.
Android SDK Components
Overview
The
different components of the Android SDK are the Eclipse program, the Android
SDK Manager,
and the Android
Virtual Device Manager and emulator. Let’s look at each in more detail.
Eclipse with Android
Development Tools Plug-in
The
actual part of the Android SDK that you will spend most of your time dealing
with is a program
called
Eclipse, which is customized specifically for use with Android through the ADT
software
plug-in.
You will enter new code, create new classes, run programs on the Android
emulator and on
real
devices from this program. On older, less capable computers, the emulator may
run so slowly that the best option would be running
the program on an actual Android device. Because we are
dealing with CPU-intensive 3D games in this book, you should use
an actual Android device to run
the
example projects (see Figure 1-1).
Figure 1-1. Eclipse with Android Development Tools plug-ins
Android SDK Manager
The Android SDK Manager allows you to download new Android
platform versions and tools through
its interface. Current tools and platform versions that are
installed are also displayed. For example,
in Figure 1-2, the Android 2.2 platform has already been
installed and is ready for use for development.
This
means that you can compile your source code to target this platform. Android Virtual Device
The Android SDK also supports a virtual device emulator (see
Figure 1-3). In many instances, you will
be able to run your Android programs on a software emulator on
your development system rather
than an actual device. However, this works best for non-graphic
intensive applications. Because
this book deals with 3D games, we will not be using this software
emulator but an actual Android
device. The Android Virtual Device Manager allows you to create
new virtual Android devices, edit
existing Android devices, delete existing devices, and start up an
existing virtual Android device.
Figure 1-3 indicates that there is a valid virtual
Android device named “Android22,” which emulates
the 2.2 version of the Android operating system (API Level 8) and
simulates the ARM CPU type. The
2.2 version of the Android operating system is important because
it is the first version that supports
OpenGL ES 2.0, which we will be using in this book to develop our
3D graphics. OpenGL is the
graphics system that allows the programmer to create 3D graphics
on the Android platform. It is
designed to be hardware-independent. That is, OpenGL graphics
commands are designed to be the
same across many different hardware platforms, such as PC, Mac,
Android, etc. The OpenGL 2.0
version of OpenGL is the first version of OpenGL that includes
programmable vertex and fragment
shaders. OpenGL ES is a subset of regular OpenGL and contains
fewer features.
Figure 1-4 depicts the actual emulator after it is
launched. The emulator depicted is the one for

version
2.2 of the Android operating system.
How to Set Up for
Development
First, you need to download and install the Java Development Kit
Version 6 or greater. The Android
development environment requires this as a prerequisite. After you
verify that it is installed and
working, then you will have to install the main components of the
Android SDK.
The quickest and easiest way to do this is to download the ADT
Bundle located at
http://developer.android.com/sdk/index.html under the “Download for Other Platforms”
section. The ADT Bundle is a downloadable zip file that contains a special
version of Eclipse with the Android
Development Tools plug-in, the Android Virtual Device Manager, the
SDK Manager and tools, as well
as the latest Android platform, and the latest Android system
image for the Android emulator. All you
have to do to install this ADT Bundle is to create a new directory
and unzip the file into it. You can
use a free tool such as 7-Zip to uncompress the file. After doing
this, you can execute the new
ADT Integrated Development Environment by executing the eclipse.exe file located in the Eclipse
directory under the main bundle directory.
Android Development
Tools Integrated Development Environment
(IDE) Overview
The
Eclipse IDE consists of several important sections that I will discuss here.
The important
sections
are the Package Explorer window, the Source Code Area window, the Outline
window, and
the
Messages windows, including a window that outputs programmer-specified debug
messages
that
is called the LogCat window. There are other Messages windows available, but
they are less
important and
won’t be covered in this section.
Package Explorer
When you start on a new Android programming project, you will
create a new package for it. In Eclipse,
there is a window called Package Explorer, located by default on
the left-hand side. This window lists
all the Android packages located in the current work space. For
example, Figure 1-5 lists packages
such
as “AndroidHelloWorld,” “AndroidHelloWorldTest,” and “ApiDemos.”

You can also expand a package so that you can access all the files
related to that package by
clicking the “plus” symbol next to the package name. The Java
source code files are located in the
“src” directory, and the project-related resources, such as
textures, 3D models, etc., are located in
the “res” (short for resources)
directory. Double-click a source code file or resource file to bring it
up for viewing inside Eclipse. Source files can also be expanded
so that you can get an overview
of the class’s variables and functions. You can double-click a
variable or function to go to that
variable or function within Eclipse’s source view window. In
Figure 1-6, there is only one function
in the “AndroidHelloWorldActivity” class, which is “onCreate.”
Finally, every Android package has
an AndroidManifest.xml file that defines such things as what
permissions are needed to run the
program, program-specific information such as version number,
program icon, and program name,
as
well as what minimum Android operating system is needed to run the program.
Source Code Area
By default, in the middle of Eclipse is the Java source code
display window. Each different Java source
code
or .xml file is displayed here in
its own tab (see Figure 1-7).

Notice that at the end of the last tab, there is a “➤” followed by “4.” What this means is that
there
are four hidden files not shown. You can access these files by
clicking the “➤4” region to bring up
a complete list of files. Files listed in boldface type are not
shown, and you can select these for
viewing by highlighting
them with your mouse pointer and left-clicking them (see Figure 1-8).

Outline
The Outline window in Eclipse is located by default on the right
side, and it lists the variables and
functions for the class that is selected in the source code
window. You can easily jump to the
corresponding class variable or class function in the source code
window by clicking the variable or
function
in the Outline window (see Figure 1-9).

In Figure 1-9, class variables or “fields” are listed
first, followed by class functions. Some examples
of class variables are HIGH_SCORES, m_BackGroundTexture, and m_Dirty. Some examples of class
functions
are FindEmptySlot(), RenderTitle(), and SortHighScoreTable().
Dalvik Debug Monitor
Server (DDMS)
Eclipse
with the ADT plug-in also provides a way to easily interface with actual
Android hardware
through
the Dalvik Debug Monitor Server or DDMS. The button to access the DDMS is on
the right
upper
corner of the Eclipse IDE. Click this button to switch views to the DDMSIn the DDMS view, you can look at the actual directories
and files on the Android device by using the
File Explorer tab located on the right-hand side of the view.
Figure 1-11 illustrates this.
On the left side, if you have an actual physical Android device connected via
the USB port, the

device is displayed in the Devices tab, as shown in Figure 1-12.
Also notice the camera icon at the upper right-hand corner of the Devices
window. If you click this

button,
then you capture a screenshot of what is currently on the Android device (see
Figure 1-13).

From
this pop-up window, you can rotate the image and save the image, if you so
desire. This is a good
way to get
screenshots for promotional images when it is time to market your application
to end users.
LogCat Window
At the bottom of the Eclipse IDE there are by default a few
rectangular windows. One of the more
important ones is called the LogCat window, and this window
displays debug and error messages
that are directly coming from a program that is running on the
Android device that is attached to your
computer
via a USB cable.
It was first published www.allitebooks.com.and http://theit-mela.blogspot.com
See You All Next Post.Thank You.
Its very good tips.thanks
ReplyDelete