content: package com.yalantis.starwars.utils.gl;
  
  import android.graphics.Bitmap;
  import android.opengl.GLES20;
  import android.opengl.GLUtils;
  
  import timber.log.Timber;
  
  import static android.opengl.GLES20.GL_CLAMP_TO_EDGE;
  import static android.opengl.GLES20.GL_NEAREST;
  import static android.opengl.GLES20.GL_TEXTURE_2D;
  import static android.opengl.GLES20.GL_TEXTURE_MAG_FILTER;
  import static android.opengl.GLES20.GL_TEXTURE_MIN_FILTER;
  import static android.opengl.GLES20.GL_TEXTURE_WRAP_S;
  import static android.opengl.GLES20.GL_TEXTURE_WRAP_T;
  import static android.opengl.GLES20.glBindTexture;
  import static android.opengl.GLES20.glGenTextures;
  import static android.opengl.GLES20.glTexParameteri;
  
  public class TextureHelper {
  
  	public static int loadTexture(final Bitmap bitmap) {
  		final int[] textureHandle = new int[1];
  
  		glGenTextures(1, textureHandle, 0);
  
  		if (textureHandle[0] != 0) {
  			// Bind to the texture in OpenGL
  			glBindTexture(GL_TEXTURE_2D, textureHandle[0]);
  
  			// Set filtering
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  
  			// Load the bitmap into the bound texture.
  			GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
  
  			// Recycle the bitmap, since its data has been loaded into OpenGL.
  			bitmap.recycle();
  		} else {
  			int errorCode = GLES20.glGetError();
              String errorString = GLUtils.getEGLErrorString(errorCode);
              RuntimeException e = new RuntimeException(errorCode + " " + errorString);
  			Timber.e(e, "");
  			throw e;
  		}
  
  		return textureHandle[0];
  	}
  
  }
  