update. still doesn't build with go-clone

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-12-04 00:36:06 -06:00
parent 8540387ab7
commit 66c4285902
7 changed files with 50 additions and 108 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.swp
go.mod
go.sum
pixelgl
pixelgl.so

View File

@ -2,11 +2,10 @@ all: plugin
ldd ../pixelgl.so
plugin:
GO111MODULE=off go build -v -x -buildmode=plugin -o ../pixelgl.so
go build -v -x -buildmode=plugin -o pixelgl.so
standalone:
GO111MODULE=off go install -v -x
pixelgl
go build -v -x
check-git-clean:
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)

View File

@ -3,3 +3,5 @@
Package gui implements a abstraction layer for Go visual elements.
This is a sample plugin. It's a skeleton intended to be used when making a new toolkit plugin.
# github.com/faiface/pixel-examples/community/seascape-shader/

30
args.go
View File

@ -28,3 +28,33 @@ func init() {
ERROR = log.NewFlag("ERROR", true, full, short, "toolkit errors")
}
var argv args
type args struct {
Width float64 `arg:"--width" default:"640" help:"window width"`
Height float64 `arg:"--height" default:"480" help:"window height"`
Filename string `arg:"--filename" help:"what .glsl file to render"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
GLdrift float32 `arg:"--drift" default:"0.01" help:"how fast things move around"`
// Fetch bool `arg:"--git-fetch" default:"false" help:"run 'git fetch' on all your repos"`
}
func (args) Version() string {
return "go-clone " + VERSION + " Built on " + BUILDTIME
}
func (a args) Description() string {
return `
git clone go repositories
Examples:
go-clone go.wit.com/apps/go-clone # simply try to git clone this
go-clone --recursive go.wit.com/apps/go-clone # recursively clone all the dependancies
go-clone --auto-work go.wit.com/apps/go-clone # if you are using a go.work file, recreate the go.work file
go-clone --go-reset # recreate every go.mod and go.sum file
go-clone --git-pull # run 'git pull' in every repo
go-clone --build # build every binary package
go-clone --install # install every binary package
`
}

View File

@ -1,84 +0,0 @@
package main
/*
This simply parses the command line arguments using the default golang
package called 'flag'. This can be used as a simple template to parse
command line arguments in other programs.
It puts everything in the 'config' package which I think is a good
wrapper around the 'flags' package and doesn't need a whole mess of
global variables
*/
import (
"flag"
"fmt"
"log"
"os"
"github.com/gookit/config"
)
var customUsage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Println("")
fmt.Println("EXAMPLES:")
fmt.Println("")
fmt.Println(os.Args[0] + " --width 1024 --height 768 --drift .1 --filename seascape.glsl")
fmt.Println(os.Args[0] + " --width 640 --height 480 --filename planetfall.glsl")
fmt.Println("")
}
func parseFlags() {
var version string
var race bool
var filename string
var width int
var height int
var glDrift float64
var guiJunk string
flag.StringVar(&version, "version", "v0.1", "Set compiled in version string")
flag.StringVar(&filename, "filename", "seascape.glsl", "path to GLSL file")
flag.StringVar(&guiJunk, "gui", "something", "redo all this code")
flag.IntVar(&width, "width", 1024, "Width of the OpenGL Window")
flag.IntVar(&height, "height", 768, "Height of the OpenGL Window")
flag.Float64Var(&glDrift, "drift", 0.01, "Speed of the gradual camera drift")
flag.BoolVar(&race, "race", race, "Use race detector")
// Set the output if something fails to stdout rather than stderr
flag.CommandLine.SetOutput(os.Stdout)
flag.Usage = customUsage
flag.Parse()
if flag.Parsed() {
log.Println("flag.Parse() worked")
} else {
log.Println("flag.Parse() failed")
}
// keys := []string{"filename", "width", "height", "drift"}
// keys := []string{"width", "height", "drift"}
// keys := []string{"height"}
// config.LoadFlags(keys)
config.Set("width", width)
config.Set("height", height)
config.Set("glDrift", glDrift)
config.Set("filename", filename)
}
func parseConfig() {
config.WithOptions(config.ParseEnv)
parseFlags()
// config.LoadOSEnv([]string{"MAIL"})
// config.LoadOSEnv([]string{"USER"})
// config.LoadOSEnv([]string{"BUILDDEBUG"})
}

20
main.go
View File

@ -10,17 +10,25 @@ package main
import (
"embed"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"github.com/faiface/pixel/pixelgl"
"github.com/gookit/config"
// "github.com/gookit/config"
)
// sent via -ldflags
var VERSION string
var BUILDTIME string
//go:embed *.glsl
var glFile embed.FS
var pp *arg.Parser
func init() {
pp = arg.MustParse(&argv)
log.Log(INFO, "Init()")
me.myTree = tree.New()
@ -42,12 +50,6 @@ func init() {
go simpleStdin()
config.Set("width", 640)
config.Set("height", 480)
config.Set("glDrift", 0.01)
// config.Set("filename", "planetfall.glsl")
config.Set("filename", "seascape.glsl")
// 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
@ -60,10 +62,6 @@ func init() {
// I assume it's for testing the code in a stand alone way
func main() {
config.Set("width", 1024)
config.Set("height", 768)
config.Set("glDrift", 0.01)
config.Set("filename", "planetfall.glsl")
// This parses the command line arguments
// parseConfig()
pixelgl.Run(run)

View File

@ -5,20 +5,17 @@ import (
"github.com/go-gl/mathgl/mgl32"
"log"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
"github.com/gookit/config"
"golang.org/x/image/colornames"
)
func run() {
// Set up window configs
log.Println("width = ", config.Int("width"), "height = ", config.String("height"))
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
Title: "Golang GLSL",
Bounds: pixel.R(0, 0, config.Float("width"), config.Float("height")),
// Bounds: pixel.R(0, 0, float64(width), float64(height)),
Bounds: pixel.R(0, 0, argv.Width, argv.Height),
VSync: true,
}
@ -35,8 +32,7 @@ func run() {
// I am putting all shader example initializing stuff here for
// easier reference to those learning to use this functionality
log.Println("Load GSGL file = ", config.String("filename"))
fragSource, err := LoadFileToString(config.String("filename"))
fragSource, err := LoadFileToString(argv.Filename)
if err != nil {
panic(err)
@ -44,8 +40,7 @@ func run() {
var uMouse mgl32.Vec4
var uTime float32
log.Println("glDrift = ", config.String("glDrift"))
var glDrift float32 = float32(config.Float("glDrift"))
var glDrift float32 = argv.GLdrift
canvas := win.Canvas()
uResolution := mgl32.Vec2{float32(win.Bounds().W()), float32(win.Bounds().H())}