Example usage for android.opengl GLES20 glGenerateMipmap

List of usage examples for android.opengl GLES20 glGenerateMipmap

Introduction

In this page you can find the example usage for android.opengl GLES20 glGenerateMipmap.

Prototype

public static native void glGenerateMipmap(int target);

Source Link

Usage

From source file:Main.java

public static void initTexture(Resources res, BitmapFactory.Options opts, int resource, int handle) {
    Bitmap bmp = BitmapFactory.decodeResource(res, resource, opts);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, handle);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    bmp.recycle();//from   w w w. j  a  v  a 2s . co m
}

From source file:Main.java

public static int loadTexture(String s) {
    Bitmap img;//from   w  ww.  j  a v  a2  s  . com
    try {
        img = BitmapFactory.decodeStream(context.getAssets().open(s));
    } catch (IOException e) {
        return 0;
    }
    int tex[] = new int[1];
    GLES20.glGenTextures(1, tex, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex[0]);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, img, 0);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    img.recycle();
    return tex[0];
}

From source file:Main.java

public static int loadTexture(String s) {
    Bitmap img;/*from w w w  .  j ava  2s .  com*/
    try {
        img = BitmapFactory.decodeStream(context.getAssets().open(s));
    } catch (IOException e) {
        return -1;
    }
    int tex[] = new int[1];
    GLES20.glGenTextures(1, tex, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex[0]);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, img, 0);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_LINEAR);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
    img.recycle();
    return tex[0];
}