diff options
| author | Jeff Carr <[email protected]> | 2024-12-05 18:49:47 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-05 18:49:47 -0600 |
| commit | 3b22b50a2b9312a27218f2096d6d0a2dae2c115d (patch) | |
| tree | 840f07ce307c3ff5ffa0cd8d049d9b2823472c3b /main.go | |
| parent | 4a72be204474e0abecd9f102c8e21b449a7e1d3e (diff) | |
using resources so it might run as a pluginv0.21.4
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -9,6 +9,8 @@ package main import ( "embed" + "io/fs" + "os" "go.wit.com/dev/alexflint/arg" "go.wit.com/log" @@ -22,10 +24,14 @@ import ( var VERSION string var BUILDTIME string -//go:embed *.glsl -var glFile embed.FS +//go:embed resources/* +var resources embed.FS + var pp *arg.Parser +// the glsl file +var glslFile string + func init() { pp = arg.MustParse(&argv) @@ -50,6 +56,7 @@ func init() { go simpleStdin() + glslFile = loadGLSL(argv.Filename) // I think this doesn't work as a goroutine because // opengl closes. This plugin probably has to wait // until there is some sort of protobuf + socket interface @@ -66,3 +73,34 @@ func main() { // parseConfig() pixelgl.Run(run) } + +// LoadFileToString loads the contents of a file into a string +func loadGLSL(filename string) string { + var err error + var data []byte + + // + data, err = os.ReadFile(filename) + if err == nil { + log.Println("found embedded file:", filename) + return string(data) + } + data, err = fs.ReadFile(resources, filename) + if len(data) == 0 { + log.Info("still could not find file", filename, err) + } else { + return string(data) + } + + filename = "resources/seascape.glsl" + log.Println("did not find embedded file:", filename, err) + data, err = fs.ReadFile(resources, filename) + if len(data) == 0 { + log.Info("still could not find file", filename) + os.Exit(-1) + } + + // return a string of the data to feed into + // canvas.SetFragmentShader(file) + return string(data) +} |
