开发者

PNG Textures not loading on HTC desire

Hi I'm developing a game for android using OpenGL es and have hit a problem:

My game loads fine in the emulator (windows xp and vista from eclipse), it also loads fine on a T-Mobile G2 (HTC Hero) however when I load it on my new HTC Desire none of the textures appear to load correctly (or at all). I'm suspecting the BitmapFactory.decode method although I have no evidence that that is the problem.

All of my textures are power of 2 and JPG textures seem to load (although they don't look great quality) but anything that is GIF or PNG just doesn't load at all except for a 2x2 red square which loads fine and one texture that maps to a 3d object but seems to fill each triangle of the mesh with the nearest colour).

This is my code for loading images:

     AssetManager am = androidContext.getAssets();
  BufferedInputStream is = null;
  try {
     is = new BufferedInputStream(am.open(fileName));

     Bitmap bitmap;

     bitmap = BitmapFactory.decodeStream(is);

     GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
     bitmap.recycle();
  } catch(IOException e) {
     Logger.global.log(Level.SEV开发者_开发技巧ERE, e.getLocalizedMessage());
  } finally {
     try {
        is.close();
     } catch(Exception e) {
        // Ignore.
     }
  }

thanks


The size is really import of the texture, for example I used a rectangle as an argument for BitmapFactory.decodeStream of 0, 0, 1024, 1024. Of course it had to be 0, 0, 1023, 1023. For a refference look at the code below, I tested it on the Desire S and Galaxy S2:

    InputStream is = context.getResources().openRawResource(resource);
    Bitmap bmp;

    gl.glBindTexture(GL10.GL_TEXTURE_2D, texID[tex]);

    // Mendatory, tells openGL how to render the texture, nearest will look sharp, smooth will look blurry
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);

    // Not mendatory, tells openGL what to do when sprite is smaller or bigger than object
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

    gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);

    try {
        BitmapFactory.Options sBitmapOptions  = new BitmapFactory.Options();
        // Set our bitmaps to 16-bit, 565 format...uhm, this looks more like 32 bit: 8888
        sBitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
        bmp = BitmapFactory.decodeStream(is, new Rect(0, 0, 1023, 1023), sBitmapOptions);

        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
        bmp.recycle();
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜