Time for action – clearing and swapping buffers

Let's clear the display buffers with a color fading from black to white:

  1. While still being in jni/GraphicsManager.cpp, refresh the screen during each update step with eglSwapBuffers().

    To have a visual feedback, change the display background color gradually with the help of glClearColor() before erasing the Framebuffer with glClear():

    ...
    status GraphicsManager::update() {
        static float clearColor = 0.0f;
        clearColor += 0.001f;
        glClearColor(clearColor, clearColor, clearColor, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
    
        if (eglSwapBuffers(mDisplay, mSurface) != EGL_TRUE) {
            Log::error("Error %d swapping buffers.", eglGetError());
            return STATUS_KO;
        } else {
            return STATUS_OK;
        }
    }
  2. Update the Android.mk file to link ...

Get Android NDK Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.