android - 如何在 opengl 中使用压缩纹理?

标签 android opengl-es

我想将 .PVR 图像用于纹理目的。
为此,我使用了 PVRtextool 并在 drawables-mdpi 中加载了我的 pvr 图像。
现在,当我在我的项目中使用它时,应用程序崩溃了。

我是不是漏掉了一些步骤?
请指导。

这是我遇到问题的加载纹理代码。 resource 包含 .pvr 格式的图像。

static void loadTexture(GL10 gl, Context context, int[] resource)
   {  
       gl.glGenTextures(n, textureIDs, 0);
       BitmapFactory.Options opts = new BitmapFactory.Options();
       opts.inScaled = false;
       for (int face = 0; face < n; face++)
       {

           gl.glBindTexture(GL10.GL_TEXTURE_2D, textureIDs[face]);

           bitmap[face] = BitmapFactory.decodeResource(
            context.getResources(), resource[face],opts); 


           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);


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

最佳答案

您不能使用 BitmapFactory.decodeResource()用那种格式。你必须使用 openRawResource()函数并传递 InputStream它返回到 ETC1Util.loadTexture()功能。

示例实现应位于 /sdk/platforms/<version>/samples/CompressedTextureActivity.java , 或者在线版本是 here.

关于android - 如何在 opengl 中使用压缩纹理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11184062/

相关文章:

android - 如何从 OnClick 事件 Android 创建一个 Observable?

java - Android NDK 使用静态库 -> 函数尚未声明

opengl-es - OpenGL ES 渲染到用户空间内存

ios - "This UIView seems to be the delegate of an NSISVariable it doesn' t 什么都不知道。这是一个内部 UIKit 错误“错误

javascript 为 webgl 加载纹理

android - Listview行requestLayout()和View回收

android - 如何在android中读取tensorflow内存映射图文件?

java - Linkedin 集成 Android

opengl-es - glGetUniformLocation 和 glGetAttribLocation 之间的区别

android - 适用于 Linux 的 BlueStacks 模拟器?