[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 4.12.1 Alpha and Keycolor in Textures

Crystal Space supports the alpha channel that can be present in some image files (like PNG and TGA).

It is important to realize that when you use alpha on an object you must sort the object back to front. That basically means you'll most likely have to use the ``alpha'` render priority (see section Render Priorities and Objects in Sectors) and also ``ztest'` for the Z-buffer usage. Also in some cases you may need to set the ``back2front'` flag if the object is a genmesh (see section Genmesh Mesh Object).

It is often hard to get things correct with such a setup so in many cases it is preferable to use a method named binary alpha. This means that a pixel is either treated as fully opaque or fully transparent - the former for alpha values greater than 50%, the latter for alpha values lower than 50%. In practice, it is probably desireable to only use 0% and 100% transparency values in the alpha channel. Also, the transparent area(s) should be filled with a color that is similar to its adjacent opaque pixels, as, due texture filtering, this color will slightly bleed into the neighboring opaque pixels. Choosing an approriate color makes this bleeding non-obvious.

The easiest way to activate binary alpha is to mark the texture as follows in your world file:

    <texture name="transparent">
        <file>mytexture.png</file>
        <alpha><binary/></alpha>
    </texture>

If you do this then this texture can be used on objects as any other texture. So the object can simply use ``object'` render priority and ``zuse'` Z-buffer mode.

An alternative way to enable binary alpha is by using a keycolor for the texture; that is, all pixels of the specified color (in the example magenta) will be rendered transparent.

    <texture name="transparent">
        <file>mytexture.png</file>
        <transparent r="1" g="0" b="1" />
    </texture>

However, using this technique is discouraged as it is less performant than the using binary alpha as described above; specifically, when loading a texture with a keycolor, CrystalSpace will scan the image for pixels of that color and set their alpha value to 0. Internally, binary alpha and keycolor work in the same way (transparency of a pixel is based on whether the alpha value is above or below 50%), however, keycolored textures come with a load-time performance penalty due to the required processing step.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ]

This document was generated using texi2html 1.76.