Compare commits

..

No commits in common. "b0b6e9772696af190c1c8bc35d7d962f8cb39ab1" and "93f9cd5359db4c9dba723ad631434138ebe0ac31" have entirely different histories.

2 changed files with 30 additions and 50 deletions

View File

@ -4,76 +4,64 @@ 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 "log"
import "os"
import "flag"
import "fmt"
import "github.com/gookit/config"
var (
version string
race bool
debug = os.Getenv("BUILDDEBUG") != ""
filename string
width int
height int
timeout = "120s"
uDrift float32
)
var customUsage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Println("")
fmt.Println("EXAMPLES:")
fmt.Println("EXAMPLE:")
fmt.Println("")
fmt.Println(os.Args[0] + " --width 1024 --height 768 --drift .1 --filename shaders/seascape.glsl")
fmt.Println(os.Args[0] + " --width 640 --height 480 --filename shaders/planetfall.glsl")
fmt.Println("seascape-shader --width 640 --height 480 --filename shaders/planetfall.glsl")
fmt.Println("")
}
func parseFlags() {
var version string
var race bool
var filename string
var width int
var height int
var glDrift float64
flag.StringVar (&version, "version", "v0.1", "Set compiled in version string")
flag.StringVar (&filename, "filename", "shaders/seascape.glsl", "path to GLSL file")
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")
var tmp float64
flag.Float64Var (&tmp, "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.SetOutput(os.Stdout)
flag.Usage = customUsage
flag.Parse()
if flag.Parsed() {
log.Println("flag.Parse() worked")
log.Println("Parsed() worked. width=",width)
} else {
log.Println("flag.Parse() failed")
log.Println("Parsed() failed. width=",width)
}
// keys := []string{"filename", "width", "height", "drift"}
// keys := []string{"width", "height", "drift"}
// if err := flag.Parse(); err != nil {
// log.Println("Example:",width)
// }
// 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"})
uDrift = float32(tmp)
log.Println("width=",width)
log.Println("height=",height)
log.Println("uDrift=",uDrift)
}

View File

@ -10,15 +10,11 @@ import (
"golang.org/x/image/colornames"
)
import "log"
import "github.com/gookit/config"
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)),
VSync: true,
}
@ -35,8 +31,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(filename)
if err != nil {
panic(err)
@ -44,8 +39,6 @@ func run() {
var uMouse mgl32.Vec4
var uTime float32
log.Println("glDrift = ", config.String("glDrift"))
var glDrift float32 = float32(config.Float("glDrift"))
canvas := win.Canvas()
uResolution := mgl32.Vec2{float32(win.Bounds().W()), float32(win.Bounds().H())}
@ -54,7 +47,7 @@ func run() {
"uResolution", &uResolution,
"uTime", &uTime,
"uMouse", &uMouse,
"uDrift", &glDrift,
"uDrift", &uDrift,
)
canvas.SetFragmentShader(fragSource)
@ -79,8 +72,7 @@ func run() {
}
func main() {
// This parses the command line arguments
parseConfig()
parseFlags()
pixelgl.Run(run)
}