Example usage for android.opengl GLUtils texSubImage2D

List of usage examples for android.opengl GLUtils texSubImage2D

Introduction

In this page you can find the example usage for android.opengl GLUtils texSubImage2D.

Prototype

public static void texSubImage2D(int target, int level, int xoffset, int yoffset, Bitmap bitmap, int format,
        int type) 

Source Link

Document

A version of texSubImage2D() that takes an explicit type parameter as defined by the OpenGL ES specification.

Usage

From source file:Main.java

/**
 * Initialize the current texture and load the specified Bitmap into
 * it.//from   w  ww  .ja v  a2 s .c o  m
 */
private static boolean loadTexture(Bitmap bmp, int allocated_width, int allocated_height) {
    int internalFormat, format, type;
    int unpackAlignment;

    switch (bmp.getConfig()) {
    case ARGB_4444:
    case ARGB_8888:
        internalFormat = format = GL_RGBA;
        type = GL_UNSIGNED_BYTE;
        unpackAlignment = 4;
        break;

    case RGB_565:
        internalFormat = format = GL_RGB;
        type = GL_UNSIGNED_SHORT_5_6_5;
        unpackAlignment = 2;
        break;

    case ALPHA_8:
        internalFormat = format = GL_ALPHA;
        type = GL_UNSIGNED_BYTE;
        unpackAlignment = 1;
        break;

    default:
        return false;
    }

    /* create an empty texture, and load the Bitmap into it */

    glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, allocated_width, allocated_height, 0, format, type, null);
    glPixelStorei(GL_UNPACK_ALIGNMENT, unpackAlignment);
    GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bmp, format, type);
    return true;
}