Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.

Commit 90e3466

Browse files
committed
load font from file
1 parent 33567ba commit 90e3466

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

main.go

+18-19
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ import (
55
"fmt"
66
"time"
77
"os"
8-
"strconv"
98
"strings"
109

1110
"github.com/veandco/go-sdl2/sdl"
1211
"github.com/yuin/gopher-lua"
1312
"github.com/muesli/gamut"
13+
"github.com/PinwheelSystem/bitmap"
1414
)
1515

16-
const version = "v0.0.2"
16+
const version = "v0.0.3"
1717
const res int = 128 // Resolution of the *screen* ("internal") . Might change later in development. (res x res, 128 x 128)
1818
const scale = 4 // Resolution scale (contributes to the size of the *window*)
1919
var palette [][]uint8 = make([][]uint8, 64) // Array of array of RGB values ([[R, G, B], [R, G, B], ...])
2020
var pixelbuf []byte = make([]byte, res * res * 4) // Pixel backbuffer (basically our VRAM)
2121
var start time.Time
22-
var font [][]uint16 = make([][]uint16, 36)
22+
var font map[string][]string
2323

2424
func main() {
2525
colors, _ := gamut.Generate(64, gamut.PastelGenerator{})
26-
font = [][]uint16{{0xf, 0x9, 0x9, 0xf, 0x9, 0x9}}
26+
bm := bitmap.New()
27+
font = bm.Load("font.png")
28+
2729
for i := uint8(0); i < 64; i++ {
2830
r, g, b, _ := colors[i].RGBA()
2931
palette[i] = []uint8{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8)}
@@ -164,21 +166,18 @@ func PWpchar(L *lua.LState) int {
164166
x := L.ToInt(2)
165167
y := L.ToInt(3)
166168

167-
switch char {
168-
case "A":
169-
xx := x
170-
yy := y
171-
for i := 0; i < 6; i++ {
172-
bin := strconv.FormatInt(int64(font[0][i]), 2)
173-
binarr := strings.Split(bin, "")
174-
175-
for _, pix := range binarr {
176-
if pix == "1" { setpixel(xx, yy, 69, 153, 77) }
177-
xx += 1
178-
}
179-
yy += 1
180-
xx = x
181-
}
169+
xx := x
170+
yy := y
171+
for i := 0; i < 8; i++ {
172+
bin := font[char][i]
173+
binarr := strings.Split(bin, "")
174+
175+
for _, pix := range binarr {
176+
if pix == "1" { setpixel(xx, yy, 69, 153, 77) }
177+
xx += 1
178+
}
179+
yy += 1
180+
xx = x
182181
}
183182

184183
return 1

0 commit comments

Comments
 (0)