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 – adapting resolution with off-screen rendering


Let's render the game scene off-screen:

  1. Change jni/GraphicsManager.hpp, followed by these steps:

    • Define new getter methods for the screen width and height with their corresponding member variables

    • Create a new function initializeRenderBuffer(), which creates an off-screen buffer to render the scene:

      ...
      class GraphicsManager {
      public:
          ...
          int32_t getRenderWidth() { return mRenderWidth; }s
          int32_t getRenderHeight() { return mRenderHeight; }
          int32_t getScreenWidth() { return mScreenWidth; }
          int32_t getScreenHeight() { return mScreenHeight; }
          GLfloat* getProjectionMatrix() { return mProjectionMatrix[0]; }
      
      ...
  2. While still being in the same file, follow these steps:

    • Declare a new RenderVertex structure with four components - x, y, u, and v

    • Define the OpenGL resources necessary for the framebuffer, namely, the texture, the vertex buffer, the shader program, and its variables:

      ...
      private:
          status initializeRenderBuffer...