O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Touch Support to Our Activity

We’ll begin by hooking into Android’s touch event system. The first thing we’ll need to do is hold onto a reference to our renderer, so let’s open up AirHockeyActivity and modify the call to setRenderer as follows:

AirHockeyTouch/src/com/airhockey/android/AirHockeyActivity.java
 
final​ AirHockeyRenderer airHockeyRenderer = ​new​ AirHockeyRenderer(this);
 
 
if​ (supportsEs2) {
 
// ...
 
glSurfaceView.setRenderer(airHockeyRenderer);

We’ll refer to this reference in our touch handler to inform the renderer of new touch events.

Listening to Touch Events

Let’s start writing our touch handler by adding the following code just before the call to setContentView:

AirHockeyTouch/src/com/airhockey/android/AirHockeyActivity.java ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required