www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: kiffa on March 22, 2013, 12:40:29 pm

Title: How to judge if a texture contains alpha?
Post by: 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:

Code: [Select]
Texture texture = TextureManager.getInstance().getTexture(name);
object3d.setTexture(name);

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

But there isn't a method like texture.containsAlpha().
Title: Re: How to judge if a texture contains alpha?
Post by: LowPolyMan on March 22, 2013, 01:12:46 pm
I'm writing a SceneLoader which has a feature: auto setting Object3D's transparency by it's texture. Codes may like that:

Code: [Select]
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) ?

Title: Re: How to judge if a texture contains alpha?
Post by: EgonOlsen on March 22, 2013, 02:21:56 pm
You can get a Texture's pixels from an ITextureEffect as well.
Title: Re: How to judge if a texture contains alpha?
Post by: 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() ?
Title: Re: How to judge if a texture contains alpha?
Post by: LowPolyMan on March 28, 2013, 10:31:40 pm
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:

Code: [Select]
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);