O'Reilly logo

Android NDK Beginner's Guide - Second Edition by Sylvain Ratabouil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – rendering a star field

Let's now see how to apply this particle effect in DroidBlaster:

  1. In jni/GraphicsManager.hpp, define a new method to load a vertex buffer.

    Add an array to store vertex buffer resources:

    ...
    class GraphicsManager {
    public:
        ...
        GLuint loadShader(const char* pVertexShader,
                const char* pFragmentShader);
        GLuint loadVertexBuffer(const void* pVertexBuffer,
                int32_t pVertexBufferSize);
    
    private:
        ...
        GLuint mShaders[32]; int32_t mShaderCount;
        GLuint mVertexBuffers[32]; int32_t mVertexBufferCount;
    
        GraphicsComponent* mComponents[32]; int32_t mComponentCount;
    };
    #endif
  2. In jni/GraphicsManager.cpp, update the constructor initialization list and free vertex buffer resources in stop():
    ... GraphicsManager::GraphicsManager(android_app* ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required