Game Development Reference
In-Depth Information
gl.glEnable(GL10.GL_CULL_FACE);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
}
private boolean mTranslucentBackground;
private Cube mCube;
private float mAngle;
}
The final piece of this puzzle is the cube itself, which has information such as dimensions,
colors, and other specifications. It works in tandem with the previous two components. Let's
see what the cube does.
Cube Class
CubeRenderer delegates drawing to the Cube class (see Listing 3-9). This class defines a
12-sided cube with 8 vertices (8 × x, y, and z coordinates), 32 colors (8 vertices × 4 ARGB
values), and 36 indices for the x, y, and z coordinates of each side. The class consists of two
methods:
Cube() : This is the class constructor. It initializes arrays for the vertices,
colors, and indices required to draw. It then uses direct Java buffers to
place the data on the native heap where the garbage collector cannot
move them. This is required by the gl*Pointer() API functions that do
the actual drawing.
draw() : To draw the cube, you simply set the vertices and colors, and
issue a call to glDrawElements using triangles ( GL_TRIANGLES ). Note that
a cube has 6 faces, 8 vertices, and 12 sides.
gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, 36
, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
Listing 3-9. Cube Class for the GL Cubes Sample
package opengl.scenes.cubes;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import javax.microedition.khronos.opengles.GL10;
/**
* A vertex shaded cube.
*/
 
Search WWH ::




Custom Search