-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadTTF.go
48 lines (40 loc) · 847 Bytes
/
loadTTF.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"io/ioutil"
"log"
"os"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
)
func loadTTF(path string, dpi float64, size float64) (font.Face, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
bytes, err := ioutil.ReadAll(file)
if err != nil {
return nil, err
}
font, err := truetype.Parse(bytes)
if err != nil {
return nil, err
}
return truetype.NewFace(font, &truetype.Options{
Size: size,
GlyphCacheEntries: 1,
}), nil
}
// InitFonts initializes fonts for the game
func (g *Game) InitFonts() {
const dpi = 72
var err error
mdataFont, err = loadTTF("./Assets/Font/LoRe.ttf", dpi, 8)
if err != nil {
log.Fatal(err)
}
mversionFont, err = loadTTF("./Assets/Font/LoRe.ttf", dpi, 8)
if err != nil {
log.Fatal(err)
}
}