summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--main.go42
-rw-r--r--psutil.go21
-rw-r--r--resources/planetfall.glsl (renamed from planetfall.glsl)0
-rw-r--r--resources/seascape.glsl (renamed from seascape.glsl)0
-rw-r--r--resources/seascape_original.glsl (renamed from seascape_original.glsl)0
-rw-r--r--seascape.go8
7 files changed, 48 insertions, 35 deletions
diff --git a/Makefile b/Makefile
index edc1823..8fa7f4e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,12 @@
-all: plugin
- ldd pixelgl.so
+all: goimports plugin
+ #ldd pixelgl.so
plugin:
- go build -v -x -buildmode=plugin -o pixelgl.so
+ GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
install:
- go build -v -x -buildmode=plugin -o pixelgl.so
+ rm -f pixelgo.so
+ go build -v -x -buildmode=plugin -o ~/go/lib/pixelgl.so
full-plugin:
GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
@@ -14,7 +15,8 @@ full-install:
GO111MODULE=off go build -v -x -buildmode=plugin -o pixelgl.so
standalone:
- go build -v -x
+ GO111MODULE=off go build -v -x
+ ./pixelgl
check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
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)
+}
diff --git a/psutil.go b/psutil.go
index 957e8dc..f7dbe4a 100644
--- a/psutil.go
+++ b/psutil.go
@@ -1,12 +1,8 @@
package main
import (
- "io/fs"
- "io/ioutil"
-
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
- "go.wit.com/log"
)
// Pixel Shader utility functions
@@ -44,20 +40,3 @@ func CenterWindow(win *pixelgl.Window) {
),
)
}
-
-// 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
-}
diff --git a/planetfall.glsl b/resources/planetfall.glsl
index d1a74e6..d1a74e6 100644
--- a/planetfall.glsl
+++ b/resources/planetfall.glsl
diff --git a/seascape.glsl b/resources/seascape.glsl
index 7a69f40..7a69f40 100644
--- a/seascape.glsl
+++ b/resources/seascape.glsl
diff --git a/seascape_original.glsl b/resources/seascape_original.glsl
index b70f887..b70f887 100644
--- a/seascape_original.glsl
+++ b/resources/seascape_original.glsl
diff --git a/seascape.go b/seascape.go
index 5e93a27..ac7151c 100644
--- a/seascape.go
+++ b/seascape.go
@@ -32,12 +32,6 @@ func run() {
// I am putting all shader example initializing stuff here for
// easier reference to those learning to use this functionality
- fragSource, err := LoadFileToString(argv.Filename)
-
- if err != nil {
- panic(err)
- }
-
var uMouse mgl32.Vec4
var uTime float32
var glDrift float32 = argv.GLdrift
@@ -52,7 +46,7 @@ func run() {
"uDrift", &glDrift,
)
- canvas.SetFragmentShader(fragSource)
+ canvas.SetFragmentShader(glslFile)
start := time.Now()