我想将 .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/