Game Development Reference
In-Depth Information
more than likely, give you terrible headache. To understand how you can maximize the return on your
investment, let's look at the general steps used to create an OpenGL application.
Any OpenGL application can be divided into the following major steps:
1. Initialization : OpenGL is a single-threaded system that requires a GLContext to be
initialized. Only one thread can access this context at a time. In EGL, this step is
subdivided as follows:
a. Get an EGL instance. In Android, this can be done using the EGLContext class:
mEgl = EGLContext.getEGL();
b. Get a default display. The display is required for the rendering process. In
Android, use this call:
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
c. Initialize the display, as follows:
int[] version = new int[2];
mEgl.eglInitialize(mEglDisplay, version);
d. You must also specify the pixel format and image depth you wish to use. The
following requests a 32bpp pixel format with an image depth of 16:
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
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
};
mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);
2. Main loop : This is usually a user-defined thread that performs or delegates
drawing operations.
3. Drawing : In the drawing process, a set of GL operations is performed for each
iteration of the loop . At the end of each iteration, buffers must be swapped to
display the rendered surface on the screen.
4. Cleanup : In this step, the GLContext is destroyed and resources released back to
the system.
All these steps can be performed in Java. So it happened that one day I wanted to port an OpenGL-
based game to Android written in C, and wondered if some steps could be done in Java and some in C. I
was very happy to discover that this is indeed possible. For example, the following steps can be
performed in Java within an Android activity:
Initialization : Get the EGL instance, initialize the default display, and set the pixel
format and image depth.
Search WWH ::




Custom Search