pixelgl/main.go

107 lines
2.1 KiB
Go

package main
/*
This is reference code for toolkit developers
The 'nocui' is a bare minimum toolkit. It's all you need
to interact with the GUI
*/
import (
"embed"
"io/fs"
"os"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"github.com/faiface/pixel/pixelgl"
// "github.com/gookit/config"
)
// sent via -ldflags
var VERSION string
var BUILDTIME string
//go:embed resources/*
var resources embed.FS
var pp *arg.Parser
// the glsl file
var glslFile string
func init() {
pp = arg.MustParse(&argv)
log.Log(INFO, "Init()")
me.myTree = tree.New()
me.myTree.PluginName = "nocui"
// me.myTree.ActionFromChannel = doAction
me.myTree.NodeAction = newaction
me.myTree.Add = Add
me.myTree.SetTitle = SetTitle
me.myTree.SetLabel = SetLabel
me.myTree.SetText = SetText
me.myTree.AddText = AddText
me.exit = false
log.Log(INFO, "Init() END")
showOptions()
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
// instead of a plugin
pixelgl.Run(run)
}
// this must be defined for plugin's, but is never run
// I assume it's for testing the code in a stand alone way
func main() {
// This parses the command line arguments
// 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)
}