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 the W Component to Create Perspective

It will be easier to understand the effects of the w component if we actually see it in action, so let’s add it to our table vertex data and see what happens. Since we’ll now be specifying the x, y, z, and w components of a position, let’s begin by updating POSITION_COMPONENT_COUNT as follows:

AirHockey3D/src/com/airhockey/android/AirHockeyRenderer.java
 
private​ ​static​ ​final​ ​int​ POSITION_COMPONENT_COUNT = 4;

We must always make sure that we’re giving OpenGL the right component count for everything that we use; otherwise we’ll either have a corrupt screen, nothing will display at all, or we might even crash our application.

The next step is to update all of our vertices:

AirHockey3D/src/com/airhockey/android/AirHockeyRenderer.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