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 ...

Get OpenGL ES 2 for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.