MasDennis/Rajawali — pull request #342 by Davhed (2013-01-30 00:05:22+00:00)
Title: Added Simple Alpha Map Material

Reason

Coding a live wallpaper to handle 4 different types of compression as well as falling back to uncompressed bitmaps was getting a bit hairy for me. ETC1 compression is the most widely available texture compression type on mobile, but it lacks support for an alpha channel. Many of the ETC1 compression tools will take an input RGBA image and will output two RGB compressed textures -- one diffuse, and one alpha map.

To support the use of ETC1 I needed to create a simple way to map alpha, and I started with extending the SimpleMaterial class in a new material class called `SimpleAlphaMaterial`.

<3> How

`AMaterial` and `TextureManager` were changed to add the enum `ALPHA` and create a corresponding `TextureType.ALPHA`.

To use this material you must add two ETC1 textures to your material/object. One of `TextureType.DIFFUSE`, and one `TextureType.ALPHA'. Your alpha map should be white(255) for fully opaque, and black(0) for fully transparent.

````java

mySimpleAlphaMat.addTexture(mTextureManager.addEtc1Texture(mContext.getResources().openRawResource(R.raw.my_etc1_diff), BitmapFactory.decodeResource(mContext.getResources(), R.drawable.my_fallback_img), TextureType.DIFFUSE));

mySimpleAlphaMat.addTexture(mTextureManager.addEtc1Texture(mContext.getResources().openRawResource(R.raw.my_etc1_alpha), BitmapFactory.decodeResource(mContext.getResources(), R.drawable.my_fallback_img), TextureType.ALPHA));

````

For each object that uses this material be sure to enable transparency:

`myObj.setTransparent(true)`

or enable blending:

````java
myObj.setBlendingEnabled(true);
myObj.setBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
````

I plan to extend the rest of the materials this way so that any material type can fully support ETC1.