ITexture LoadTextureAsAlpha(string sm3directory, TdfParser.Section terrainsection, string texturesectionname)
 {
     TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
     string texturename = Path.Combine( sm3directory, texturesection.GetStringValue("file") );
     LogFile.GetInstance().WriteLine(texturename);
     return GlTexture.FromAlphamapFile(texturename);
 }
        List<MapTextureStage> LoadTextureStages(string sm3directory, TdfParser.Section terrainsection)
        {
            int numstages = terrainsection.GetIntValue("numtexturestages");
            List<MapTextureStage> stages = new List<MapTextureStage>();
            for (int i = 0; i < numstages; i++)
            {
                TdfParser.Section texstagesection = terrainsection.SubSection("texstage" + i);
                string texturename = texstagesection.GetStringValue("source");
                string blendertexturename = texstagesection.GetStringValue("blender");
                string operation = texstagesection.GetStringValue("operation").ToLower();

                int tilesize;
                ITexture texture = LoadTexture( sm3directory, terrainsection, texturename, out tilesize );
                if (operation == "blend")
                {
                    ITexture blendtexture = LoadTextureAsAlpha(sm3directory, terrainsection, blendertexturename);
                    stages.Add( new MapTextureStage(MapTextureStage.OperationType.Blend, tilesize, texture, blendtexture) );
                }
                else // todo: add other operations
                {
                    stages.Add( new MapTextureStage(MapTextureStage.OperationType.Replace, tilesize, texture ) );
                }
            }
            Terrain.GetInstance().texturestages = stages;
            return stages;
        }
 ITexture LoadTexture( string sm3directory, TdfParser.Section terrainsection, string texturesectionname, out int tilesize )
 {
     TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
     string texturename = Path.Combine( sm3directory, texturesection.GetStringValue("file") );
     LogFile.GetInstance().WriteLine(texturename);
     tilesize = texturesection.GetIntValue("tilesize");
     return GlTexture.FromFile(texturename);
 }