OpenGL Animation Example

You can easily accommodate OpenGL animation in the new Android release by changing the rendering mode on the GLSurfaceView object (see Listing 13-7).

Listing 13-7. Specifying Continuous-Rendering Mode

//get a GLSurfaceView GLSurfaceView openGLView;

//Set the mode to continuous draw mode openGLView.setRenderingMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY)j

(Note that we're showing you how to change the rendering mode here because we had specified RENDERMODE_WHEN_DIRTY in the previous section. As we mentioned, RENDERMODE_ CONTINUOUSLY is in fact the default setting, so animation is enabled by default.) Once the rendering mode is continuous, it is up to the renderer's onDraw method to do what's necessary to effect animation. To demonstrate this, we will show you an example where the triangle drawn in the previous example is rotated in a circular fashion. This example has the following two files:

• AnimatedTriangleActivity.java, which is a simple activity to host the GLSurfaceView

• AnimatedSimpleTriangleRenderer.java, which is responsible for animated drawing Let us consider each of these files.

+1 0

Post a comment