jPCT-AE - a 3d engine for Android > Support
How to judge if a texture contains alpha?
(1/1)
kiffa:
I'm writing a SceneLoader which has a feature: auto setting Object3D's transparency by it's texture. Codes may like that:
--- Code: ---Texture texture = TextureManager.getInstance().getTexture(name);
object3d.setTexture(name);
if(texture.containsAlpha()){
object3d.setTransparency(0xff);
}
--- End code ---
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:
--- Code: ---Texture texture = TextureManager.getInstance().getTexture(name);
object3d.setTexture(name);
if(texture.containsAlpha()){
object3d.setTransparency(0xff);
}
--- End code ---
But there isn't a method like texture.containsAlpha().
--- End quote ---
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:
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() ?
--- End quote ---
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: ---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);
--- End code ---
Navigation
[0] Message Index
Go to full version