private void init(ShaderI shader, Texture2DI texture, Stream stream, string metricsFileName, Loader.LoadedCallbackMethod loadedCallback)
{
try
{
// load characters
var metrics = new FontMetrics();
metrics.Load(stream);
Characters = new Character[metrics.Characters.Length];
for (int i = 0; i != metrics.Characters.Length; ++i)
{
var character = metrics.Characters[i];
Characters[i] = new Character(character.Key, new Vector2(character.X, character.Y), new Vector2(character.Width, character.Height));
}
// get shader variables
this.texture = texture;
this.shader = shader;
shaderCamera = shader.Variable("Camera");
shaderPosition = shader.Variable("Position");
shaderSize = shader.Variable("Size");
shaderPositionUV = shader.Variable("PositionUV");
shaderSizeUV = shader.Variable("SizeUV");
texelOffset = shader.Variable("TexelOffset");
shaderColor = shader.Variable("Color");
shaderTexture = shader.Resource("DiffuseTexture");
// create buffers
var layoutDesc = BufferLayoutDescAPI.New(BufferLayoutTypes.Position2);
layout = BufferLayoutAPI.New(this, shader, layoutDesc);
var Indices = new int[6]
{
0, 1, 2,
0, 2, 3
};
var Vertices = new float[8]
{
0, 0,
0, 1,
1, 1,
1, 0,
};
indexBuffer = IndexBufferAPI.New(this, BufferUsages.Default, Indices);
vertexBuffer = VertexBufferAPI.New(this, layoutDesc, BufferUsages.Default, VertexBufferTopologys.Triangle, Vertices);
}
catch (Exception e)
{
FailedToLoad = true;
Loader.AddLoadableException(e);
Dispose();
if (loadedCallback != null)
{
loadedCallback(this, false);
}
}
Loaded = true;
if (loadedCallback != null)
{
loadedCallback(this, true);
}
}