2024-02-19 07:16:10 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-19 08:10:21 -06:00
|
|
|
"io/fs"
|
2024-02-19 07:16:10 -06:00
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/faiface/pixel"
|
|
|
|
"github.com/faiface/pixel/pixelgl"
|
2024-02-19 08:10:21 -06:00
|
|
|
"go.wit.com/log"
|
2024-02-19 07:16:10 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// Pixel Shader utility functions
|
|
|
|
|
|
|
|
// EasyBindUniforms does all the work for you, just pass in a
|
|
|
|
// valid array adhering to format: String, Variable, ...
|
|
|
|
//
|
|
|
|
// example:
|
|
|
|
//
|
2024-02-19 08:10:21 -06:00
|
|
|
// var uTimeVar float32
|
|
|
|
// var uMouseVar mgl32.Vec4
|
2024-02-19 07:16:10 -06:00
|
|
|
//
|
2024-02-19 08:10:21 -06:00
|
|
|
// EasyBindUniforms(win.GetCanvas(),
|
|
|
|
// "u_time", &uTimeVar,
|
|
|
|
// "u_mouse", &uMouseVar,
|
|
|
|
// )
|
2024-02-19 07:16:10 -06:00
|
|
|
func EasyBindUniforms(c *pixelgl.Canvas, unifs ...interface{}) {
|
|
|
|
if len(unifs)%2 != 0 {
|
|
|
|
panic("needs to be divisable by 2")
|
|
|
|
}
|
|
|
|
for i := 0; i < len(unifs); i += 2 {
|
|
|
|
|
|
|
|
c.SetUniform(unifs[i+0].(string), unifs[i+1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CenterWindow will... center the window
|
|
|
|
func CenterWindow(win *pixelgl.Window) {
|
|
|
|
x, y := pixelgl.PrimaryMonitor().Size()
|
|
|
|
width, height := win.Bounds().Size().XY()
|
|
|
|
win.SetPos(
|
|
|
|
pixel.V(
|
|
|
|
x/2-width/2,
|
|
|
|
y/2-height/2,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// LoadFileToString loads the contents of a file into a string
|
|
|
|
func LoadFileToString(filename string) (string, error) {
|
2024-02-19 08:10:21 -06:00
|
|
|
embedf, err1 := fs.ReadFile(glFile, filename)
|
|
|
|
if err1 == nil {
|
|
|
|
log.Println("found embedded file:", filename)
|
|
|
|
return string(embedf), nil
|
|
|
|
} else {
|
|
|
|
log.Println("did not find embedded file:", filename)
|
|
|
|
log.Println("err", err1)
|
|
|
|
}
|
|
|
|
b, err := ioutil.ReadFile("/tmp/" + filename)
|
2024-02-19 07:16:10 -06:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(b), nil
|
|
|
|
}
|