Creating an EGL Surface#

Using a native window created earlier and a suitable configuration, an EGL surface is created that OpenGL ES calls are rendered to.

Note

Surface objects in EGL are the objects to which OpenGL ES can render. They can generally be considered an abstraction of a native window, however this is not always the case.

There are three main surface types in EGL, which can all be used in the same way once created but work slightly differently:

  • Window Surfaces - These are created from a native window and are drawn to the screen.

  • Pixmap Surfaces - These are also created from a native windowing system, but are offscreen so are not displayed to the user.

  • PBuffer Surfaces - These are created directly within EGL, and like Pixmap Surfaces are offscreen so are not displayed.

The offscreen surfaces are useful for non-rendering contexts and in certain other scenarios. For most applications the main surface used will be a window surface as performed below.

This is a simple one-step process that EGL makes very easy. The application can call eglCreateWindowSurface and pass the previously created EGLDisplay, EGLConfig, and the native window. The final parameter is a list of attributes of the surface, but this can be set to NULL.

_eglSurface = eglCreateWindowSurface(_eglDisplay, config, _surfaceData.window, NULL);

If this fails, try without including the native window.

if (_eglSurface == EGL_NO_SURFACE)
{
    eglGetError(); // Clear error
    _eglSurface = eglCreateWindowSurface(_eglDisplay, config, NULL, NULL);
}

Check for any EGL Errors after an EGL call.

if (!test-egl-error(_surfaceData, "eglCreateWindowSurface"))
{
    return false;
}
return true;