Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load and bind texture in OpenGL ES?

So, I have a texture in my res/drawable-hdpi (text.png, for example) folder, how I can load this texture and bind it with glBindTexture?

like image 236
Vlad Markushin Avatar asked Jan 24 '26 20:01

Vlad Markushin


1 Answers

Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.text);
int[] texId = new int[1];
GLES20.glGenTextures(1, texId, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId[0]);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
  1. Decode resource to bitmap
  2. Generate texture
  3. Bind Texture
  4. Upload texture
  5. Set minification filter for completeness
like image 97
Tim Avatar answered Jan 26 '26 12:01

Tim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!