mirror of
https://github.com/Kugelschieber/go-game.git
synced 2026-01-18 06:40:28 +00:00
Added texture mapped font rendering.
This commit is contained in:
113
demo/text/assets/victor.json
Normal file
113
demo/text/assets/victor.json
Normal file
@@ -0,0 +1,113 @@
|
||||
[
|
||||
{"char":"a", "x": 0, "y": 0, "offset": 0},
|
||||
{"char":"b", "x": 1, "y": 0, "offset": 0},
|
||||
{"char":"c", "x": 2, "y": 0, "offset": 0},
|
||||
{"char":"d", "x": 3, "y": 0, "offset": 0},
|
||||
{"char":"e", "x": 4, "y": 0, "offset": 0},
|
||||
{"char":"f", "x": 5, "y": 0, "offset": 0},
|
||||
{"char":"g", "x": 6, "y": 0, "offset": 0},
|
||||
{"char":"h", "x": 7, "y": 0, "offset": 0},
|
||||
{"char":"i", "x": 8, "y": 0, "offset": 0},
|
||||
{"char":"j", "x": 9, "y": 0, "offset": 0},
|
||||
{"char":"k", "x": 10, "y": 0, "offset": 0},
|
||||
{"char":"l", "x": 11, "y": 0, "offset": 0},
|
||||
{"char":"m", "x": 12, "y": 0, "offset": 0},
|
||||
{"char":"n", "x": 13, "y": 0, "offset": 0},
|
||||
{"char":"o", "x": 14, "y": 0, "offset": 0},
|
||||
{"char":"p", "x": 15, "y": 0, "offset": 0},
|
||||
{"char":"q", "x": 16, "y": 0, "offset": 0},
|
||||
{"char":"r", "x": 17, "y": 0, "offset": 0},
|
||||
{"char":"s", "x": 18, "y": 0, "offset": 0},
|
||||
{"char":"t", "x": 19, "y": 0, "offset": 0},
|
||||
{"char":"u", "x": 20, "y": 0, "offset": 0},
|
||||
{"char":"v", "x": 21, "y": 0, "offset": 0},
|
||||
{"char":"w", "x": 22, "y": 0, "offset": 0},
|
||||
{"char":"x", "x": 23, "y": 0, "offset": 0},
|
||||
{"char":"y", "x": 24, "y": 0, "offset": 0},
|
||||
{"char":"z", "x": 25, "y": 0, "offset": 0},
|
||||
|
||||
{"char":"A", "x": 0, "y": 0, "offset": 0},
|
||||
{"char":"B", "x": 1, "y": 0, "offset": 0},
|
||||
{"char":"C", "x": 2, "y": 0, "offset": 0},
|
||||
{"char":"D", "x": 3, "y": 0, "offset": 0},
|
||||
{"char":"E", "x": 4, "y": 0, "offset": 0},
|
||||
{"char":"F", "x": 5, "y": 0, "offset": 0},
|
||||
{"char":"G", "x": 6, "y": 0, "offset": 0},
|
||||
{"char":"H", "x": 7, "y": 0, "offset": 0},
|
||||
{"char":"I", "x": 8, "y": 0, "offset": 0},
|
||||
{"char":"J", "x": 9, "y": 0, "offset": 0},
|
||||
{"char":"K", "x": 10, "y": 0, "offset": 0},
|
||||
{"char":"L", "x": 11, "y": 0, "offset": 0},
|
||||
{"char":"M", "x": 12, "y": 0, "offset": 0},
|
||||
{"char":"N", "x": 13, "y": 0, "offset": 0},
|
||||
{"char":"O", "x": 14, "y": 0, "offset": 0},
|
||||
{"char":"P", "x": 15, "y": 0, "offset": 0},
|
||||
{"char":"Q", "x": 16, "y": 0, "offset": 0},
|
||||
{"char":"R", "x": 17, "y": 0, "offset": 0},
|
||||
{"char":"S", "x": 18, "y": 0, "offset": 0},
|
||||
{"char":"T", "x": 19, "y": 0, "offset": 0},
|
||||
{"char":"U", "x": 20, "y": 0, "offset": 0},
|
||||
{"char":"V", "x": 21, "y": 0, "offset": 0},
|
||||
{"char":"W", "x": 22, "y": 0, "offset": 0},
|
||||
{"char":"X", "x": 23, "y": 0, "offset": 0},
|
||||
{"char":"Y", "x": 24, "y": 0, "offset": 0},
|
||||
{"char":"Z", "x": 25, "y": 0, "offset": 0},
|
||||
|
||||
{"char":"0", "x": 26, "y": 0, "offset": 0},
|
||||
{"char":"1", "x": 27, "y": 0, "offset": 0},
|
||||
{"char":"2", "x": 28, "y": 0, "offset": 0},
|
||||
{"char":"3", "x": 29, "y": 0, "offset": 0},
|
||||
{"char":"4", "x": 30, "y": 0, "offset": 0},
|
||||
{"char":"5", "x": 31, "y": 0, "offset": 0},
|
||||
{"char":"6", "x": 32, "y": 0, "offset": 0},
|
||||
{"char":"7", "x": 33, "y": 0, "offset": 0},
|
||||
{"char":"8", "x": 34, "y": 0, "offset": 0},
|
||||
{"char":"9", "x": 35, "y": 0, "offset": 0},
|
||||
|
||||
{"char":"ö", "x": 36, "y": 0, "offset": 0},
|
||||
{"char":"ä", "x": 37, "y": 0, "offset": 0},
|
||||
{"char":"ü", "x": 38, "y": 0, "offset": 0},
|
||||
{"char":"ß", "x": 39, "y": 0, "offset": 0},
|
||||
|
||||
{"char":"Ö", "x": 36, "y": 0, "offset": 0},
|
||||
{"char":"Ä", "x": 37, "y": 0, "offset": 0},
|
||||
{"char":"Ü", "x": 38, "y": 0, "offset": 0},
|
||||
|
||||
{"char":",", "x": 68, "y": 0, "offset": -0.25},
|
||||
{"char":";", "x": 69, "y": 0, "offset": 0},
|
||||
{"char":".", "x": 70, "y": 0, "offset": 0},
|
||||
{"char":":", "x": 71, "y": 0, "offset": 0},
|
||||
{"char":"-", "x": 72, "y": 0, "offset": 0},
|
||||
{"char":"_", "x": 73, "y": 0, "offset": 0},
|
||||
|
||||
{"char":"^", "x": 40, "y": 0, "offset": 0},
|
||||
{"char":"°", "x": 41, "y": 0, "offset": 0},
|
||||
{"char":"!", "x": 42, "y": 0, "offset": 0},
|
||||
{"char":"\"", "x": 43, "y": 0, "offset": 0},
|
||||
{"char":"§", "x": 44, "y": 0, "offset": 0},
|
||||
{"char":"$", "x": 45, "y": 0, "offset": 0},
|
||||
{"char":"%", "x": 46, "y": 0, "offset": 0},
|
||||
{"char":"&", "x": 47, "y": 0, "offset": 0},
|
||||
{"char":"/", "x": 48, "y": 0, "offset": 0},
|
||||
{"char":"(", "x": 49, "y": 0, "offset": 0},
|
||||
{"char":")", "x": 50, "y": 0, "offset": 0},
|
||||
{"char":"=", "x": 51, "y": 0, "offset": 0},
|
||||
{"char":"?", "x": 52, "y": 0, "offset": 0},
|
||||
{"char":"`", "x": 53, "y": 0, "offset": 0},
|
||||
{"char":"²", "x": 54, "y": 0, "offset": 0},
|
||||
{"char":"³", "x": 55, "y": 0, "offset": 0},
|
||||
{"char":"{", "x": 56, "y": 0, "offset": 0},
|
||||
{"char":"[", "x": 57, "y": 0, "offset": 0},
|
||||
{"char":"]", "x": 58, "y": 0, "offset": 0},
|
||||
{"char":"}", "x": 59, "y": 0, "offset": 0},
|
||||
{"char":"\\", "x": 60, "y": 0, "offset": 0},
|
||||
{"char":"+", "x": 61, "y": 0, "offset": 0},
|
||||
{"char":"*", "x": 62, "y": 0, "offset": 0},
|
||||
{"char":"~", "x": 63, "y": 0, "offset": 0},
|
||||
{"char":"#", "x": 64, "y": 0, "offset": 0},
|
||||
{"char":"<", "x": 65, "y": 0, "offset": 0},
|
||||
{"char":">", "x": 66, "y": 0, "offset": 0},
|
||||
{"char":"|", "x": 67, "y": 0, "offset": 0},
|
||||
{"char":"'", "x": 68, "y": 0, "offset": 0},
|
||||
{"char":"'", "x": 69, "y": 0, "offset": 0}
|
||||
]
|
||||
BIN
demo/text/assets/victor.png
Normal file
BIN
demo/text/assets/victor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -2,45 +2,63 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/DeKugelschieber/go-game"
|
||||
"github.com/go-gl/gl/v4.5-core/gl"
|
||||
)
|
||||
|
||||
const (
|
||||
font_path = "src/github.com/DeKugelschieber/go-game/demo/text/assets/font.png"
|
||||
font_path = "src/github.com/DeKugelschieber/go-game/demo/text/assets/victor.png"
|
||||
font_json = "src/github.com/DeKugelschieber/go-game/demo/text/assets/victor.json"
|
||||
)
|
||||
|
||||
type Game struct{}
|
||||
|
||||
func (g *Game) Setup() {
|
||||
// load texture
|
||||
/*_, err := goga.LoadRes(gopher_path)
|
||||
pngLoader, ok := goga.GetLoaderByExt("png").(*goga.PngLoader)
|
||||
|
||||
if !ok {
|
||||
panic("Could not get PNG loader")
|
||||
}
|
||||
|
||||
pngLoader.KeepData = true
|
||||
pngLoader.Filter = gl.NEAREST
|
||||
_, err := goga.LoadRes(font_path)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create sprite
|
||||
tex, err := goga.GetTex("gopher.png")
|
||||
pngLoader.KeepData = false
|
||||
pngLoader.Filter = gl.LINEAR
|
||||
|
||||
// create font
|
||||
tex, err := goga.GetTex("victor.png")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
sprite := goga.NewSprite(tex)
|
||||
renderer, ok := goga.GetSystemByName("spriteRenderer").(*goga.SpriteRenderer)
|
||||
font := goga.NewFont(tex, 16)
|
||||
|
||||
if err := font.FromJson(font_json, true); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// setup renderer
|
||||
renderer, ok := goga.GetSystemByName("textRenderer").(*goga.TextRenderer)
|
||||
|
||||
if !ok {
|
||||
panic("Could not find renderer")
|
||||
}
|
||||
|
||||
renderer.Add(sprite.Actor, sprite.Pos2D, sprite.Tex)
|
||||
renderer.Font = font
|
||||
|
||||
culling, ok := goga.GetSystemByName("culling2d").(*goga.Culling2D)
|
||||
|
||||
if !ok {
|
||||
panic("Could not find culling")
|
||||
}
|
||||
|
||||
culling.Add(sprite.Actor, sprite.Pos2D)*/
|
||||
// create and add text
|
||||
text := goga.NewText(font, "Hello, World!_")
|
||||
text.Size = goga.Vec2{16, 16}
|
||||
text.Pos = goga.Vec2{20, 20}
|
||||
renderer.Prepare(text)
|
||||
renderer.Add(text.Actor, text.Pos2D, text.TextComponent)
|
||||
}
|
||||
|
||||
func (g *Game) Update(delta float64) {}
|
||||
|
||||
Reference in New Issue
Block a user