Java Code Examples for javax.microedition.khronos.opengles.GL10#glGenTextures()

The following examples show how to use javax.microedition.khronos.opengles.GL10#glGenTextures() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLBitmap.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public void loadGLTexture(GL10 gl, Context context) {
    // loading texture
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.ic_launcher_background);

    // generate one texture pointer
    gl.glGenTextures(1, textures, 0);
    // ...and bind it to our array
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

    // create nearest filtered texture
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    // Use Android GLUtils to specify a two-dimensional texture image from
    // our bitmap
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

    // Clean up
    bitmap.recycle();
}
 
Example 2
Source File: Model3D.java    From augmentedreality with Apache License 2.0 6 votes vote down vote up
@Override
public void init(GL10 gl){
	int[]  tmpTextureID = new int[1];

	Iterator<Material> materialI = model.getMaterials().values().iterator();
	while (materialI.hasNext()) {
		Material material = (Material) materialI.next();
		if(material.hasTexture()) {

			gl.glGenTextures(1, tmpTextureID, 0);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, tmpTextureID[0]);
			textureIDs.put(material, tmpTextureID[0]);
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, material.getTexture(),0);
			material.getTexture().recycle();
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 
		}
	}
}
 
Example 3
Source File: LabelMaker.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Call to initialize the class.
 * Call whenever the surface has been created.
 *
 * @param gl
 */
public void initialize(GL10 gl) {
    mState = STATE_INITIALIZED;
    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);
    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    // Use Nearest for performance.
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_NEAREST);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_CLAMP_TO_EDGE);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);
}
 
Example 4
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private int createTargetTexture(GL10 gl, int width, int height) {
            int texture;
            int[] textures = new int[1];
            gl.glGenTextures(1, textures, 0);
            texture = textures[0];
            gl.glBindTexture(GL10.GL_TEXTURE_2D, texture);
            gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, width, height, 0,
                    GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, null);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
                    GL10.GL_NEAREST);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D,
                    GL10.GL_TEXTURE_MAG_FILTER,
                    GL10.GL_LINEAR);
            gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
                    GL10.GL_REPEAT);
            gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
                    GL10.GL_REPEAT);
;            return texture;
        }
 
Example 5
Source File: TGAGLSurfaceView.java    From TGAReader with MIT License 5 votes vote down vote up
public int createTGATexture(GL10 gl, String path) {
	int texture = 0;
	try {
		
		InputStream is = getContext().getAssets().open(path);
		byte [] buffer = new byte[is.available()];
		is.read(buffer);
		is.close();
		
		int [] pixels = TGAReader.read(buffer, TGAReader.ABGR);
		int width = TGAReader.getWidth(buffer);
		int height = TGAReader.getHeight(buffer);
		
		int [] textures = new int[1];
		gl.glGenTextures(1, textures, 0);
		
		gl.glEnable(GL_TEXTURE_2D);
		gl.glBindTexture(GL_TEXTURE_2D, textures[0]);
		gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

		IntBuffer texBuffer = IntBuffer.wrap(pixels);
		gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texBuffer);
		
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		gl.glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		
		texture = textures[0];
		
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	
	return texture;
}
 
Example 6
Source File: CubeMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private int generateCubeMap(GL10 gl, int[] resourceIds) {
    checkGLError(gl);
    int[] ids = new int[1];
    gl.glGenTextures(1, ids, 0);
    int cubeMapTextureId = ids[0];
    gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, cubeMapTextureId);
    gl.glTexParameterf(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP,
            GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP,
            GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

    for (int face = 0; face < 6; face++) {
        InputStream is = getResources().openRawResource(resourceIds[face]);
        Bitmap bitmap;
        try {
            bitmap = BitmapFactory.decodeStream(is);
        } finally {
            try {
                is.close();
            } catch(IOException e) {
                Log.e("CubeMap", "Could not decode texture for face " + Integer.toString(face));
            }
        }
        GLUtils.texImage2D(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0,
                bitmap, 0);
        bitmap.recycle();
    }
    checkGLError(gl);
    return cubeMapTextureId;
}
 
Example 7
Source File: Texture.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public static Texture createTexture(Bitmap bitmap, FlipRenderer renderer, GL10 gl) {
  Texture t = new Texture();
  t.renderer = renderer;

  Assert.assertTrue("bitmap should not be null or recycled",
                    bitmap != null && !bitmap.isRecycled());

  int potW = Integer.highestOneBit(bitmap.getWidth() - 1) << 1;
  int potH = Integer.highestOneBit(bitmap.getHeight() - 1) << 1;

  t.contentWidth = bitmap.getWidth();
  t.contentHeight = bitmap.getHeight();
  t.width = potW;
  t.height = potH;

  if (AphidLog.ENABLE_DEBUG) {
    AphidLog.d("createTexture: %d, %d; POT: %d, %d", bitmap.getWidth(), bitmap.getHeight(), potW,
            potH);
  }

  gl.glGenTextures(1, t.id, 0);
  gl.glBindTexture(GL_TEXTURE_2D, t.id[0]);

  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  switch (bitmap.getConfig()) {
    case ARGB_8888:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ARGB_4444:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA,
                      GL_UNSIGNED_SHORT_4_4_4_4, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case RGB_565:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, potW, potH, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
                      null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ALPHA_8:
    default:
      throw new RuntimeException(
          "Unrecognized bitmap format for OpenGL texture: " + bitmap.getConfig());
  }

  FlipRenderer.checkError(gl);

  return t;
}
 
Example 8
Source File: Texture.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public static Texture createTexture(Bitmap bitmap, FlipRenderer renderer, GL10 gl) {
  Texture t = new Texture();
  t.renderer = renderer;

  Assert.assertTrue("bitmap should not be null or recycled",
                    bitmap != null && !bitmap.isRecycled());

  int potW = Integer.highestOneBit(bitmap.getWidth() - 1) << 1;
  int potH = Integer.highestOneBit(bitmap.getHeight() - 1) << 1;

  t.contentWidth = bitmap.getWidth();
  t.contentHeight = bitmap.getHeight();
  t.width = potW;
  t.height = potH;

  if (AphidLog.ENABLE_DEBUG) {
    AphidLog.d("createTexture: %d, %d; POT: %d, %d", bitmap.getWidth(), bitmap.getHeight(), potW,
            potH);
  }

  gl.glGenTextures(1, t.id, 0);
  gl.glBindTexture(GL_TEXTURE_2D, t.id[0]);

  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  switch (bitmap.getConfig()) {
    case ARGB_8888:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ARGB_4444:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA,
                      GL_UNSIGNED_SHORT_4_4_4_4, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case RGB_565:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, potW, potH, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
                      null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ALPHA_8:
    default:
      throw new RuntimeException(
          "Unrecognized bitmap format for OpenGL texture: " + bitmap.getConfig());
  }

  FlipRenderer.checkError(gl);

  return t;
}
 
Example 9
Source File: SpriteTextRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
            GL10.GL_FASTEST);

    gl.glClearColor(.5f, .5f, .5f, 1);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_CLAMP_TO_EDGE);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    InputStream is = mContext.getResources()
            .openRawResource(R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();

    if (mLabels != null) {
        mLabels.shutdown(gl);
    } else {
        mLabels = new LabelMaker(true, 256, 64);
    }
    mLabels.initialize(gl);
    mLabels.beginAdding(gl);
    mLabelA = mLabels.add(gl, "A", mLabelPaint);
    mLabelB = mLabels.add(gl, "B", mLabelPaint);
    mLabelC = mLabels.add(gl, "C", mLabelPaint);
    mLabelMsPF = mLabels.add(gl, "ms/f", mLabelPaint);
    mLabels.endAdding(gl);

    if (mNumericSprite != null) {
        mNumericSprite.shutdown(gl);
    } else {
        mNumericSprite = new NumericSprite();
    }
    mNumericSprite.initialize(gl, mLabelPaint);
}
 
Example 10
Source File: MatrixPaletteRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
            GL10.GL_FASTEST);

    gl.glClearColor(.5f, .5f, .5f, 1);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_CLAMP_TO_EDGE);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    InputStream is = mContext.getResources()
            .openRawResource(R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();

    mGrid = generateWeightedGrid(gl);
}
 
Example 11
Source File: TriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
            GL10.GL_FASTEST);

    gl.glClearColor(.5f, .5f, .5f, 1);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D,
            GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_CLAMP_TO_EDGE);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    InputStream is = mContext.getResources()
            .openRawResource(R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
}