From 3b22b50a2b9312a27218f2096d6d0a2dae2c115d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 5 Dec 2024 18:49:47 -0600 Subject: using resources so it might run as a plugin --- main.go | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index d92b0b4..27e62cd 100644 --- a/main.go +++ b/main.go @@ -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) +} -- cgit v1.2.3