How to judge if a texture contains alpha?

Started by kiffa, March 22, 2013, 12:40:29 PM

Previous topic - Next topic

kiffa

I'm writing a SceneLoader which has a feature: auto setting Object3D's transparency by it's texture. Codes may like that:


Texture texture = TextureManager.getInstance().getTexture(name);
object3d.setTexture(name);

if(texture.containsAlpha()){
  object3d.setTransparency(0xff);
}


But there isn't a method like texture.containsAlpha().

LowPolyMan

Quote from: kiffa on March 22, 2013, 12:40:29 PM
I'm writing a SceneLoader which has a feature: auto setting Object3D's transparency by it's texture. Codes may like that:


Texture texture = TextureManager.getInstance().getTexture(name);
object3d.setTexture(name);

if(texture.containsAlpha()){
  object3d.setTransparency(0xff);
}


But there isn't a method like texture.containsAlpha().

Mabe load/convert as a bitmap, get the pixels as array, check all first byte value's of 4 (ARGB) ?


EgonOlsen

You can get a Texture's pixels from an ITextureEffect as well.

kiffa

#3
Both of the above are not easy to use(for my case). Could you add the method Texture.containsAlpha() ?

LowPolyMan

Quote from: kiffa on March 27, 2013, 04:03:03 AM
Both of the above are not easy to use(for my case). Could you add the method Texture.containsAlpha() ?

A Bitmap object in Java/Android has a 'hasAlpha()' flag. So you could load your texture as bitmap and then add it as texture.

Something like the following would do the trick:


Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.YOURBITMAP);
if (bmp.hasAlpha()==true)
{
  //This bitmap has alpha ..
}
//Now you can pass your bitmap as texture
Texture YOURTEXTURE = new Texture(bmp);