Drawing to the Screen

With the final connections in place, we’re now ready to start drawing to the screen! We’ll draw the table first, and then we’ll draw the dividing line and the mallets.

Drawing the Table

Let’s add the following code after the call to glClear, at the end of onDrawFrame:

AirHockey1/src/com/airhockey/android/AirHockeyRenderer.java
 
glUniform4f(uColorLocation, 1.0f, 1.0f, 1.0f, 1.0f);
 
glDrawArrays(GL_TRIANGLES, 0, 6);

First we update the value of u_Color in our shader code by calling glUniform4f. Unlike attributes, uniforms don’t have default components, so if a uniform is defined as a vec4 in our shader, we need to provide all four components. We want to start out by drawing a white table, so we set red, green, and blue to 1.0f ...

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.