protected override void load()
{
// clarabie - nov 18, 2008
// modified this to check for an existing material instead of always
// creating a new one. Allows more flexibility, but also specifically allows us to
// solve the problem of XNA not having fixed function support
_material = (Material)MaterialManager.Instance.GetByName( "Fonts/" + _name );
if ( _material == null )
{
// create a material for this font
_material = (Material)MaterialManager.Instance.Create( "Fonts/" + _name, Group );
TextureUnitState unitState = null;
bool blendByAlpha = false;
if ( _fontType == FontType.TrueType )
{
#if !( XBOX || XBOX360 )
// create the font bitmap on the fly
createTexture();
// a texture layer was added in CreateTexture
unitState = _material.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 );
blendByAlpha = true;
#endif
}
else
{
// load this texture
// TODO In general, modify any methods like this that throw their own exception rather than returning null, so the caller can decide how to handle a missing resource.
_texture = TextureManager.Instance.Load( Source, Group, TextureType.TwoD, 0 );
blendByAlpha = texture.HasAlpha;
// pre-created font images
unitState = Material.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( Source );
}
// set texture addressing mode to Clamp to eliminate fuzzy edges
if ( unitState != null )
unitState.SetTextureAddressingMode( TextureAddressing.Clamp );
// set up blending mode
if ( blendByAlpha )
{
_material.SetSceneBlending( SceneBlendType.TransparentAlpha );
}
else
{
// assume black background here
_material.SetSceneBlending( SceneBlendType.Add );
}
}
}