Game Development Reference
In-Depth Information
Listing 6-1 has the following two public functions and one private function, which drive the
entire process:
nanoGL_Init() : This function is meant to be called from your code
to initialize the NanoGL interface, and it must be called before
any OpenGL operations. Its job is to load the OpenGL ES library
and create an interface between itself and OpenGL ES by calling
CreateGlEsInterface . After this process completes, any OpenGL calls
(such as immediate mode drawing) will be filtered through this interface
and sent transparently to the OpenGL ES backend.
nanoGL_Destroy() : This function can be called when you are done with
OpenGL and want to release resources. It is usually called when your
program terminates.
CreateGlEsInterface() : This is where all the magic happens. This is a
private function that loads the OpenGL interface in a very clever way,
as explained in the “Quake for Android Architecture” section.
nanoGL_Init starts by searching for an OpenGL ES library to load.
const char * lib1 = "libGLESv1_CM.so";
const char * lib2 = "libGLESv2.so";
const char * driver;
if ( ! loadDriver(lib1) ) {
// failed to load libGLESv1_CM.so
if ( ! loadDriver(lib2) ) {
// failed to load libGLESv2.so. Abort.
return 0;
}
else
driver = lib2; // use libGLESv2.so
}
else
driver = lib1; // use libGLESv1_CM.so
nanoGL_Init 's search order starts with libGLESv1_CM.so , which is the main OpenGL ES
library. If libGLESv1_CM.so cannot be found (this should not happen in any standard Android
device), then it attempts to load libGLESv2.so (OpenGL ES version 2). If both fail, it bails out
and returns an error. To load the library, NanoGL uses loadDriver , which wraps the UNIX
system call.
dlopen(name, RTLD_NOW | RTLD_LOCAL)
This system call loads a dynamic library from the OS search path and returns a pointer to
the loaded library. With this pointer, you can then load symbols (functions) and other data
structures from the library using the system call.
void * function = dlsym(library, "function_name")
 
Search WWH ::




Custom Search