mirror of https://github.com/liamg/aminal.git
package default font into the binary
This commit is contained in:
parent
f024c1aa24
commit
c6a152c1e2
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"image"
|
||||
"image/draw"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
|
||||
"github.com/go-gl/gl/all-core/gl"
|
||||
"github.com/golang/freetype"
|
||||
|
@ -36,12 +36,7 @@ type color struct {
|
|||
}
|
||||
|
||||
//LoadFont loads the specified font at the given scale.
|
||||
func LoadFont(file string, scale float32, windowWidth int, windowHeight int) (*Font, error) {
|
||||
fd, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer fd.Close()
|
||||
func LoadFont(reader io.Reader, scale float32, windowWidth int, windowHeight int) (*Font, error) {
|
||||
|
||||
// Configure the default font vertex and fragment shaders
|
||||
program, err := newProgram(vertexFontShader, fragmentFontShader)
|
||||
|
@ -56,7 +51,7 @@ func LoadFont(file string, scale float32, windowWidth int, windowHeight int) (*F
|
|||
resUniform := gl.GetUniformLocation(program, gl.Str("resolution\x00"))
|
||||
gl.Uniform2f(resUniform, float32(windowWidth), float32(windowHeight))
|
||||
|
||||
return LoadTrueTypeFont(program, fd, scale)
|
||||
return LoadTrueTypeFont(program, reader, scale)
|
||||
}
|
||||
|
||||
//SetColor allows you to set the text color to be used when you draw the text
|
||||
|
|
15
gui/gui.go
15
gui/gui.go
|
@ -1,10 +1,12 @@
|
|||
package gui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/gobuffalo/packr"
|
||||
"github.com/liamg/raft/glfont"
|
||||
|
||||
"github.com/go-gl/gl/all-core/gl"
|
||||
|
@ -121,7 +123,7 @@ func (gui *GUI) Render() error {
|
|||
gl.BindFragDataLocation(program, 0, gl.Str("outColour\x00"))
|
||||
|
||||
gui.logger.Debugf("Loading font...")
|
||||
if err := gui.loadFont("./fonts/Hack-Regular.ttf"); err != nil {
|
||||
if err := gui.loadDefaultFont(); err != nil {
|
||||
return fmt.Errorf("Failed to load font: %s", err)
|
||||
}
|
||||
|
||||
|
@ -244,8 +246,15 @@ func (gui *GUI) Render() error {
|
|||
|
||||
}
|
||||
|
||||
func (gui *GUI) loadFont(path string) error {
|
||||
font, err := glfont.LoadFont(path, gui.fontScale, gui.width, gui.height)
|
||||
func (gui *GUI) loadDefaultFont() error {
|
||||
|
||||
box := packr.NewBox("./packed-fonts")
|
||||
fontBytes, err := box.MustBytes("Hack-Regular.ttf")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Packaged font could not be read: %s", err)
|
||||
}
|
||||
|
||||
font, err := glfont.LoadFont(bytes.NewReader(fontBytes), gui.fontScale, gui.width, gui.height)
|
||||
if err != nil {
|
||||
return fmt.Errorf("LoadFont: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue