Game Development Reference
In-Depth Information
Next, the perspective is translated in the z axis by three units toward the eye viewpoint (also known
as the camera):
gl.glTranslatef(0, 0, -3.0f);
The next two instructions tell the pipeline to rotate the perspective in the y and x axes by an angle
given in radians (0-6.28, 0 meaning zero degrees, and 6.28, meaning 360 degrees).
gl.glRotatef(mAngle, 0, 1, 0);
gl.glRotatef(mAngle * 0.25f, 1, 0, 0);
Next, it requests that vertices and colors be rendered. These are defined within the Cube class:
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
Then the cube is drawn:
mCube.draw(gl);
The perspective is rotated again in the y and z axes, and translated half a unit away from the eye:
gl.glRotatef(mAngle * 2.0f, 0, 1, 1);
gl.glTranslatef(0.5f, 0.5f, 0.5f);
The second cube is drawn, and the angle of rotation is increased for the next iteration.
mCube.draw(gl);
mAngle += 1.2f;
The int[] getConfigSpec() method initializes the pixel format and the depth of the display. The
pixel format describes the size of the ARGB values used to describe a pixel. The depth indicates the
maximum number of colors used. For example, the following integer array requests 32 bits per pixel
(ARGB 32bpp) with a depth of 16 (2^16 colors).
int[] configSpec = {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_NONE
};
The following are two other interesting methods in the cube renderer:
void sizeChanged(GL10 gl, int width, int height) : This method fires when the
size of the viewport changes. It scales the cubes by setting the ratio of the
projection matrix and resizing the viewport.
Search WWH ::




Custom Search