简体   繁体   中英

how to use compressed texture in opengl?

I want to use .PVR image for texture purpose.
For this, I used PVRtextool and loaded my pvr image in drawables-mdpi.
Now, when i use this in my project the app just crashes.

Am I missing some step?
Please guide.

Here is the load texture code where I'm getting problem. resource contains the image in .pvr format.

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();
}
]

You can't use BitmapFactory.decodeResource() with that format. You have to use the openRawResource() function and pass the InputStream it returns to the ETC1Util.loadTexture() function.

A sample implementation should be at /sdk/platforms/<version>/samples/CompressedTextureActivity.java , or an online version is here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM