Graphics Programs Reference
In-Depth Information
In the previous chapters, I showed you various instances where the Android SDK
eliminates most of our workload. Yet again, the SDK makes it possible to access an-
other useful functionality with just a few lines of code.
By calling the public method requestRender() of the GLSurfaceView class,
we can render a frame on demand. But we can request rendering in this way
only if we have set the render mode as RENDERMODE_WHEN_DIRTY . We can
set the render mode by calling the public method setRenderMode() after we
have set the renderer ( Listing 6-1 ). By passing the argument GLSur-
faceView.RENDERMODE_WHEN_DIRTY , the renderer only renders when the
surface is created, or when requestRender() is called.
Note Listing 6-1 is not the complete implementation of the
onCreate() method from the GL RENDER MODE application.
Listing
6-1. GL RENDER MODE/src/com/apress/android/glrendermode/
Main.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_surfaceView = new GLSurfaceView(this);
_surfaceView.setEGLContextClientVersion(2);
_surfaceView.setRenderer(new GLES20Renderer());
_surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
setContentView(_surfaceView);
The GL RENDER MODE application ( Chapter6/glrendermode.zip ) from
the source code for this chapter demonstrates on-demand rendering of frames. This
application is almost identical to the TOUCH ROTATION application ( Chapter2/
touchrotation.zip ). As shown in Listing 6-2 , rendering can be explicitly re-
quested ( _surfaceView.requestRender() ) every time the 3D graphics have
to be updated by any desired event.
Listing 6-2. GL RENDER MODE/src/com/apress/android/glrendermode/
Main.java
 
 
 
 
Search WWH ::




Custom Search