small medium large xlarge

OpenGL ES 2 for Android: A Quick-Start Guide


Cover image for OpenGL ES 2 for Android

OpenGL ES 2 for Android

A Quick-Start Guide


Android is booming like never before, with millions of devices shipping every day. It’s never been a better time to learn how to create your own 3D games and live wallpaper for Android. You’ll find out all about shaders and the OpenGL pipeline, and discover the power of OpenGL ES 2.0, which is much more feature-rich than its predecessor. If you can program in Java and you have a creative vision that you’d like to share with the world, then this is the book for you.

Printed in full color.

Customer Reviews

Kevin’s book is stuffed full of useful code and explanations, to the point of being inspirational.
The math/matrix stuff is the best I have ever read on the topic. If you already know Java
well and want to break into 3D graphics, this book is perfect.

- John Horton and author of the Android math league app Math Legends

Cuts out the academic fluff and teaches you what you need to become productive quickly.
I wish I had access to such a clear, concise, and humorous book when I first learned OpenGL.

- Mark F. Guerra

Developer, GLWallpaperService library for OpenGL

An amazing introduction to Android graphics programming, covering all the topics that give
headaches to OpenGL beginners with such extensive detail that you’ll be perfectly prepared
to implement your own ideas.

- Carsten Haubold

Maintainer, NeHe OpenGL tutorials

I wish I had this book when I first started programming Android games. It’s well written
and up-to-date.

- Owen Alanzo Hogarth

President, Team Blubee, Inc.

I am greatly impressed by this book and would gladly recommend it to any programming
enthusiast or anyone who’s ever dreamed of making a game.

- Tibor Simic

See All Reviews

Choose Your Format(s)

  • $25.00 In Stock
  • Ebooks are DRM free.

  • Ebook delivery options.

About this Title

Pages: 346
Published: 2013-06-20
Release: P1.0 (2013-06-19)
ISBN: 978-1-93778-534-5

This book will teach you everything you need to know to create compelling graphics on Android. You’ll learn the basics of OpenGL by building a simple game of air hockey, and along the way, you’ll see how to initialize OpenGL and program the graphics pipeline using shaders. Each lesson builds upon the one before it, as you add colors, shading, 3D projections, touch interaction, and more.

Then, you’ll find out how to turn your idea into a live wallpaper that can run on the home screen. You’ll learn about more advanced effects involving particles, lighting models, and the depth buffer. You’ll understand what to look for when debugging your program, and what to watch out for when deploying to the market.

OpenGL can be somewhat of a dark art to the uninitiated. As you read this book, you’ll learn each new concept from first principles. You won’t just learn about a feature; you’ll also understand how it works, and why it works the way it does. Everything you learn is forward-compatible with the just-released OpenGL ES 3, and you can even apply these techniques to other platforms, such as iOS or HTML5 WebGL.

What You Need

Preferably an Android phone or tablet that supports OpenGL ES 2.

Top Five OpenGL ES Tips

1) Avoid expensive operations on the UI and rendering threads.

To avoid frame rate stutters or the dreaded “Application not responding” dialog from appearing, expensive operations should be run asynchronously in a background thread. This is especially important when it comes to the rendering thread, as rendering at 30 frames per second means that each frame has to complete in about 33 milliseconds to avoid frame stutters.

Garbage collection is an expensive operation that happens non-deterministically and can cause rendering stalls, so to avoid this, you’ll also want to minimize object allocation during a frame to reduce pressure on the garbage collector. You may even see benefits to doing a manual GC at certain points in the application.

2) Do expensive texture and shader loads during intermissions.

Some expensive operations need to be done on the rendering thread, such as texture loads and shader compilations. These operations can cause noticeable stuttering if they happen in the middle of rendering, so to avoid this, preload these resources at opportune times, such as when the game / application is loaded, or at the beginning of each level.

3) Take advantage of the libraries out there.

There are many libraries out there that support OpenGL ES 2.0 development without boxing you into a framework or a closed-source middleware solution. Libgdx is one of these libraries, and by using a library like libgdx, you can more easily port your code to other platforms, as well as take advantage of the library’s math classes and asset loading management.

4) Read the documentation

The OpenGL specs and manuals are available for free from Each GPU vendor also shares a wealth of free information on how to use their GPUs, and as you read the documentation, you’ll find that they generally share a lot of advice in common, such as “minimize state switches” and “avoid discard in a fragment shader.” Reading these documents and specs will give you a lot more insight into how the GPUs work at a lower level, and will help you understand what the pitfalls are, and how to avoid premature pessimization when writing your OpenGL code.

5) Focus on what will impress the end user

Sometimes it’s easy to lose sight of the end goal, and to become focused on optimizing areas that won’t make much of a difference to the end user. Does it matter if we get this shader to execute 2% faster? Or will we make much more of a visual impact by finding a better artist? Find out what the most important areas are, and then focus on improving those first.

Contents & Extracts

  • Welcome to OpenGL ES for Android!
  • Getting Started
    • Installing the Tools
    • Creating Our First Program
    • Initializing OpenGL
    • Creating a Renderer Class
    • Using Static Imports
    • A Review
  • A Simple Game of Air Hockey
    • Defining Vertices and Shaders
      • Why Air Hockey?
      • Don’t Start From Scratch — Reusing Our Project
      • Defining the Structure of Our Air Hockey Table
      • Making the Data Accessible to OpenGL
      • Introducing the OpenGL Pipeline
      • The OpenGL Color Model
      • A Review
    • Compiling Shaders and Drawing to the Screen excerpt
      • Loading Shaders
      • Compiling Shaders
      • Linking Shaders Together into an OpenGL Program
      • Making the Final Connections
      • Drawing to the Screen
      • A Review
      • Exercises
    • Adding Color and Shade
      • Smooth Shading
      • Introducting Triangle Fans
      • Adding a New Color Attribute
      • Rendering with the new color attribute
      • A Review
      • Exercises
    • Adjusting to the Screen’s Aspect Ratio
      • We Have an Aspect Ratio Problem
      • Working With a Virtual Coordinate Space
      • Linear Algebra 101
      • Defining an Orthographic Projection
      • Adding an Orthographic Projection
      • A Review
      • Exercises
    • Entering the Third Dimension excerpt
      • The Art of 3D
      • How Opengl Transforms a Coordinate from the Shader to the Screen
      • Adding the W Component to Create Perspective
      • Moving from an Orthographic to an Perspective Projection
      • Defining a Perspective Projection
      • Creating a Projection Matrix In Our Code
      • Switching to a Projection Matrix
      • Adding Rotation
      • A Review
      • Exercises
    • Adding Detail with Textures
      • Understanding Textures
      • Loading Textures into OpenGL
      • Creating a New Set of Shaders
      • Creating a New Class Structure for Our Vertex Data
      • Adding Classes for Our Shader Programs
      • Drawing Our Texture
      • A Review
      • Exercises
    • Building Simple Objects
      • Combining Triangle Strips and Triangle Fans
      • Adding a Geometry Class
      • Adding an Object Builder
      • Updating Our Objects
      • Updating Shaders
      • Integrating Our Changes
      • A Review
      • Exercises
    • Adding Touch Feedback
      • Adding Touch Support to Our Activity
      • Adding Intersection Tests
      • Moving Around an Object by Dragging
      • Adding Collision Detection
      • A Review and Wrapup
      • Exercises
  • Bringing Things to Life
    • Spicing Things Up With Particles
      • Creating a Set of Shaders for a Simple Particle System
      • Adding the Particle System
      • Drawing the Particle System
      • Spreading out the Particles
      • Adding Gravity
      • Mixing the Particles With Additive Blending
      • Customizing the Appearance of Our Points
      • Drawing Each Point as a Sprite
      • A Review
      • Exercises
    • Adding a Skybox
      • Creating a Skybox
      • Loading a Cube Map into OpenGL
      • Creating a Cube
      • Adding a Skybox Shader Program
      • Adding the Skybox to Our Scene
      • Panning the Camera Around the Scene
      • A Review
      • Exercises
    • Adding Terrain excerpt
      • Creating a Heightmap
      • Creating Vertex and Index Buffer Objects
      • Loading in the Heightmap
      • Drawing the Heightmap
      • Occluding Hidden Objects
      • A Review
      • Exercises
    • Light Up the World
    • Live Wallpapers
    • Taking the Next Step


Kevin Brothaler is the founder of Digipom, a mobile software development shop. He has extensive experience in Android development, and he also manages Learn OpenGL ES, an online set of OpenGL tutorials for Android and WebGL.