如何在OpenGL ES中加载和绑定纹理?

3

我在res/drawable-hdpi(例如text.png)文件夹中有一个纹理,我该如何加载这个纹理并使用glBindTexture绑定它?


我尝试使用R类加载它。 - Vlad Markushin
1个回答

9
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. 解码资源为位图
  2. 生成纹理
  3. 绑定纹理
  4. 上传纹理
  5. 设置缩小过滤器以完善

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接