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 – generating an OpenGL texture


The image buffer filled by libpng now contains raw texture data. The next step is to generate a texture from it:

  1. Let's continue our previous method which is GraphicsManager::loadTexture().

    Generate a new texture identifier with glGenTextures().

    Indicate that we are working on a texture with glBindTexture().

    Configure texture parameters with glTexParameteri() to specify the way a texture is filtered and wrapped. Use GL_NEAREST, as smoothing is not essential for a 2D game without zoom effects. Texture repetition is also not necessary and can be prevented with GL_CLAMP_TO_EDGE:

    ...
        png_destroy_read_struct(&pngPtr, &infoPtr, NULL);
        delete[] rowPtrs;
    
        GLenum errorResult;
        glGenTextures(1, &texture);
        glBindTexture(GL_TEXTURE_2D, texture);
        // Set-up texture properties.
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
            GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
            GL_NEAREST...