2010-05-19 130 views
2

嗨,我开发采用了android OpenGL ES的游戏,并纷纷创出问题:PNG纹理不加载在HTC渴望

我的游戏加载在模拟器(Windows XP和Vista从日食)的罚款,这也在T-Mobile G2(HTC Hero)上加载效果不错,但是当我将其加载到我的新HTC Desire上时,没有任何纹理显示为正确加载(或根本不加载)。我怀疑BitmapFactory.decode方法,虽然我没有证据表明这是问题。

我所有的纹理都是2的幂,JPG纹理似乎加载(虽然它们看起来质量不是很好),但任何GIF或PNG都不会加载,除非加载了2×2的红色方块罚款和一个纹理映射到一个3d对象,但似乎用最接近的颜色填充网格的每个三角形)。

这是我加载图片代码:

 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.SEVERE, e.getLocalizedMessage()); 
    } finally { 
    try { 
     is.close(); 
    } catch(Exception e) { 
     // Ignore. 
    } 
    } 

感谢

回答

1

我有同样的问题。对我而言 - 只有当png具有透明度时才会发生。 这一切都开始发生时,我升级到2.2。之前进行的纹理做工精细,即使他们是不是2

功率但现在它是完全随机的。我使用透明背景在GIMP中创建了一个png文件。用刷子画了一些线条,并在Android应用中显示黑色。然后我编辑它,再添加3条线,它加载好。然后我做了一些修改,它不会再渲染:S。

我测试了它在一些示例应用程序,以排除我的编码错误(http://insanitydesign.com/wp/projects/nehe-android-ports/ - 混合例子),只是改变了混合功能,我的需求。

它的行为就像我的应用程序。

有没有人找到某种解决方法?

+0

一个解决方法是使用Bitmap.createScaledBitmap为“比例”位图以完全相同的大小。这通常使它更快乐。 – 2011-12-26 11:34:48

0

大小实际上是纹理的导入,例如我使用矩形作为参数为0,0,1024,1024的BitmapFactory.decodeStream。当然,它必须是0,0,1023,1023。一个REFFERENCE看看下面的代码,我测试它的欲望S和银河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. 
     } 
    }