Author Topic: How to judge if a texture contains alpha?  (Read 954 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
How to judge if a texture contains alpha?
« 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().

Offline LowPolyMan

  • byte
  • *
  • Posts: 25
    • View Profile
Re: How to judge if a texture contains alpha?
« Reply #1 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) ?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to judge if a texture contains alpha?
« Reply #2 on: March 22, 2013, 02:21:56 pm »
You can get a Texture's pixels from an ITextureEffect as well.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: How to judge if a texture contains alpha?
« Reply #3 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() ?
« Last Edit: March 27, 2013, 04:04:38 am by kiffa »

Offline LowPolyMan

  • byte
  • *
  • Posts: 25
    • View Profile
Re: How to judge if a texture contains alpha?
« Reply #4 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);