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 – using STL containers


Let's now replace raw arrays with standard STL containers by following these steps:

  1. Open the jni/GraphicsManager.hpp header and include the headers:

    • Vector, which defines an STL container encapsulating C arrays (with a few more interesting features such as dynamic resizing)

    • Map, which encapsulates the equivalent of a Java HashMap (that is, an associative array)

    Then, remove the textureResource member in the TextureProperties structure. Use a map container instead of a raw array for mTextures (prefixed with the std namespace). The first parameter is the key type and the second the value type.

    Finally, replace all the other raw arrays with a vector, as shown in the following:

    ...
    #include <android_native_app_glue.h>
    #include <GLES2/gl2.h>
    #include <EGL/egl.h>
    
    #include <map>
    #include <vector>
    ...
    struct TextureProperties {
        GLuint texture;
        int32_t width;
        int32_t height;
    };
    
    class GraphicsManager {
        ...
        // Graphics...