Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 the EGL and GLESv2 libraries:

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LS_CPP=$(subst $(1)/,,$(wildcard $(1)/*.cpp))
    LOCAL_MODULE := droidblaster
    LOCAL_SRC_FILES := $(call LS_CPP,$(LOCAL_PATH...