summaryrefslogtreecommitdiff
path: root/psutil.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-19 07:16:10 -0600
committerJeff Carr <[email protected]>2024-02-19 07:16:10 -0600
commitf4605dbbd165348362ea38b6313b0818196cc675 (patch)
tree9ea94dd731a70809c84703930e07dc480fff8b7d /psutil.go
pulled out from my fork of upstream repo
Diffstat (limited to 'psutil.go')
-rw-r--r--psutil.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/psutil.go b/psutil.go
new file mode 100644
index 0000000..2fb370e
--- /dev/null
+++ b/psutil.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+ "io/ioutil"
+
+ "github.com/faiface/pixel"
+ "github.com/faiface/pixel/pixelgl"
+)
+
+// Pixel Shader utility functions
+
+// EasyBindUniforms does all the work for you, just pass in a
+// valid array adhering to format: String, Variable, ...
+//
+// example:
+//
+// var uTimeVar float32
+// var uMouseVar mgl32.Vec4
+//
+// EasyBindUniforms(win.GetCanvas(),
+// "u_time", &uTimeVar,
+// "u_mouse", &uMouseVar,
+// )
+//
+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) {
+ b, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return "", err
+ }
+ return string(b), nil
+}