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

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

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