Before you can do any kind of rendering, you must
establish a connection to a display.

In this sample application, you will use the default display.

egl_disp = eglGetDisplay(EGL_DEFAULT_DISPLAY);

Initialize the EGL display.

You will be able to do little with the EGL display
until it's been initialized. The second and third
arguments of eglInitialize() are both
set to NULL because OpenGL ES 1.X is
supported by all versions of EGL; therefore it isn't
necessary to check for the major and minor version
numbers.

Then you can use eglChooseConfigs() to
choose your EGL configuration. The function
eglChooseConfigs() is probably the
most complicated function of EGL; there are many
attributes that can be specified, each with its own
matching rules, default value, and sorting order. It's
easy to get confused with all the special rules ending
up with the wrong configuration, or no configuration,
without understanding why. Be aware of this fact when
you are specifying your EGL configuration attributes.

Now, create an OpenGL ES rendering context. Among other
things, this context keeps track of the OpenGL ES state.
You don't need to specify the current rendering API with
the eglBindApi() function because
OpenGL ES is the default rendering API.

The third argument to eglCreateContext()
is another EGL rendering context with which you wish to
share data. Pass EGL_NO_CONTEXT to indicate that you
won't need any of the textures or vertex buffer objects
created in another EGL rendering context.

The last argument to eglCreateContext()
is an attribute list that you can use to specify an API
version number. You would use it to override the
EGL_CONTEXT_CLIENT_VERSION value
from 1 to 2 if you were writing
an OpenGL ES 2.X application.

Now that you've created a native platform window, you
can use it to create an EGL on-screen rendering surface.
You'll be able to use this surface as the target of your
OpenGL ES rendering. You'll use the same EGL display and
EGL configuration to create the EGL surface as you used
to set the properties on your native window. The EGL
configuration needs to be compatible with the one used
to create the window.

Bind the EGL context to the current rendering thread and to
a draw-and-read surface.

In this application, you want to draw to the EGL surface
and not really care about where you read from. Since
EGL doesn't allow specifying EGL_NO_SURFACE
for only the read surface, you will use egl_surf
for both drawing and reading. Once eglMakeCurrent()
completes successfully, all OpenGL ES calls will be executed
on the context and the surface you provided as arguments.

rc = eglMakeCurrent(egl_disp, egl_surf, egl_surf, egl_ctx);

Set the EGL swap interval.

The eglSwapInterval() function specifies
the minimum number of video frame periods per buffer swap
for the window associated with the current context. So,
if the interval is 0, the application renders as fast as
it can. Interval values of 1 or more limit the rendering
to fractions of the display's refresh rate. (For example,
60, 30, 20, 15, etc. frames per second in the case of a
display with a refresh rate of 60 Hz.)

Perform the rendering only if your window is
visible. This will leave the CPU and GPU
available to other applications and make the
system more responsive while your window is
invisible.

In this example, the function render()
is a utility function that renders the background, sets
the color to use for text rendering, renders the text
onto the screen, and updates the screen (posts the new
frame).