-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentUtils.cs
32 lines (30 loc) · 958 Bytes
/
ContentUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.Xna.Framework.Graphics;
using SpriteFontPlus;
using System.IO;
class ContentUtils
{
/**
* Load a texture from image file (e.g png, jpeg, bmp).
*/
public static Texture2D Loadtexture(GraphicsDevice graphicsDevice, string fname)
{
FileStream fileStream = new FileStream(fname, FileMode.Open);
Texture2D texture = Texture2D.FromStream(graphicsDevice, fileStream);
fileStream.Dispose();
return texture;
}
/**
* Load a font from TTF file.
*/
public static SpriteFont LoadFont(GraphicsDevice graphicsDevice, string fname)
{
return TtfFontBaker.Bake(File.ReadAllBytes(fname), 20, 1024, 1024, new[]
{
CharacterRange.BasicLatin,
CharacterRange.Latin1Supplement,
CharacterRange.LatinExtendedA,
CharacterRange.Cyrillic
}
).CreateSpriteFont(graphicsDevice);
}
}