summaryrefslogtreecommitdiff
path: root/psutil.go
blob: 957e8dcf343c1966b32d8418d554427a121a3491 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main

import (
	"io/fs"
	"io/ioutil"

	"github.com/faiface/pixel"
	"github.com/faiface/pixel/pixelgl"
	"go.wit.com/log"
)

// 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) {
	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)
	if err != nil {
		return "", err
	}
	return string(b), nil
}