PNG texts are not loaded as desired by HTC
Hi I am developing an Android game using OpenGL es and am facing the problem:
My game loads fine in the emulator (windows xp and vista by eclipse), it also charges fine on the T-Mobile G2 (HTC Hero), however, when I load it on the new HTC Desire, none of the textures load correctly (or at all ). I suspect the BitmapFactory.decode method, although I have no evidence that this is the problem.
All of my textures are at power 2 and JPG textures seem to load (although they don't look great), but anything GIF or PNG just doesn't load at all, except for a 2x2 red square which loads fine and one texture that displays in 3D object, but seems to fill each mesh triangle with the nearest color).
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.SEVERE, e.getLocalizedMessage());
} finally {
try {
is.close();
} catch(Exception e) {
// Ignore.
}
}
thanks
a source to share
I have the same problem. For me this only happens when the png has transparency. It all started when I upgraded to 2.2. Before the textures worked fine, even if they weren't power 2.
But now it is completely random. I am creating a png file in GIMP with transparent backgroud. I drew a few lines with a paintbrush and the android app has a black screen Then I edited it, added 3 more lines and it loaded fine. Then I made another modification and it won't show up again: S.
I tested it in some sample app to rule out my coding mistakes ( http://insanitydesign.com/wp/projects/nehe-android-ports/ - mixing example), just changed the mixing function to my needs.
It behaves exactly the same as my application.
Has anyone found any workaround?
a source to share
Size is really a texture import, for example I used a rectangle as an argument for BitmapFactory.decodeStream 0, 0, 1024, 1024. Of course it should be 0, 0, 1023, 1023. For refference, look at the code below, I checked it for 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.
}
}
a source to share