Game Development Reference
In-Depth Information
Figure 10-1.
A red triangle (front) and a green triangle (back) in 3D space
The red triangle is in front of the green triangle. It is possible to say “in front� because the
camera is located at the origin looking down the negative z axis by default in OpenGL ES (which
actually doesn't have the notion of a camera). The green triangle is also shifted a little to the right
so that we can see a portion of it when viewed from the front. It should be overlapped by the red
triangle for the most part. Listing 10-2 shows the code for rendering this scene.
Listing 10-2. Vertices3Test.java; Drawing Two Triangles
package
com.badlogic.androidgames.gl3d;
import
javax.microedition.khronos.opengles.GL10;
import
com.badlogic.androidgames.framework.Game;
import
com.badlogic.androidgames.framework.Screen;
import
com.badlogic.androidgames.framework.gl.Vertices3;
import
com.badlogic.androidgames.framework.impl.GLGame;
import
com.badlogic.androidgames.framework.impl.GLScreen;
public class
Vertices3Test
extends
GLGame {
public
Screen getStartScreen() {
return new
Vertices3Screen(
this
);
}
class
Vertices3Screen
extends
GLScreen {
Vertices3 vertices;
public
Vertices3Screen(Game game) {
super
(game);
vertices =
new
Vertices3(glGraphics, 6, 0,
true
,
false
);
vertices.setVertices(
new float
[] { −0.5f, -0.5f, -3, 1, 0, 0, 1,
0.5f, -0.5f, -3, 1, 0, 0, 1,
0.0f, 0.5f, -3, 1, 0, 0, 1,