Closing Out OpenGL at the End of the program

In addition to disassociating the window surface, you should close out the OpenGL ES resources at the end of a program. Listing 10-5 shows the sequence you need to use; note that it includes the content from Listing 10-4 at the beginning.

Listing 10-5. Closing Out OpenGL ES Resources //Destroy surface mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); mEgl.eglDestroySurface(mEglDisplay,

//Destroy context mEgl.eglDestroyContext(mEglDisplay,

//Disassociate display mEgl.eglTerminate(mEglDisplay);

Now you know all the basics necessary to start coding with OpenGL ES APIs. You learned how to position the camera, work with world coordinates, and map those coordinates to the physical screen. You know what APIs to use to draw basic figures. You also know how to initialize OpenGL ES on Android.

Because the initialization necessary to start using the OpenGL ES drawing APIs is extensive, we recommend you encapsulate this initialization code into a test harness. You can then use this test harness again and again with multiple OpenGL ES programming efforts so that you don't need to think about or repeat the initialization.

This approach is similar to the approach taken by Android in the 1.5 SDK. In this approach, we will cover how to do this within the confines of the 1.0 and 1.1 releases. In Chapter 13, we will cover how the 1.5 SDK provides almost all of this out of the box. Reimple-menting this test harness using the 1.5 SDK becomes very simple. Even if you care only about 1.5, we strongly recommend that you at least read this section to understand the motivation for the test harness.

The next section will show you how to design and build this OpenGL test harness, and it will provide a few specific drawing examples that use it.

0 0

Post a comment