Compare commits
No commits in common. "b0b6e9772696af190c1c8bc35d7d962f8cb39ab1" and "93f9cd5359db4c9dba723ad631434138ebe0ac31" have entirely different histories.
b0b6e97726
...
93f9cd5359
|
@ -4,76 +4,64 @@ package main
|
||||||
This simply parses the command line arguments using the default golang
|
This simply parses the command line arguments using the default golang
|
||||||
package called 'flag'. This can be used as a simple template to parse
|
package called 'flag'. This can be used as a simple template to parse
|
||||||
command line arguments in other programs.
|
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 "log"
|
||||||
import "os"
|
import "os"
|
||||||
import "flag"
|
import "flag"
|
||||||
import "fmt"
|
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() {
|
var customUsage = func() {
|
||||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println("EXAMPLES:")
|
fmt.Println("EXAMPLE:")
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println(os.Args[0] + " --width 1024 --height 768 --drift .1 --filename shaders/seascape.glsl")
|
fmt.Println("seascape-shader --width 640 --height 480 --filename shaders/planetfall.glsl")
|
||||||
fmt.Println(os.Args[0] + " --width 640 --height 480 --filename shaders/planetfall.glsl")
|
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFlags() {
|
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 (&version, "version", "v0.1", "Set compiled in version string")
|
||||||
|
|
||||||
flag.StringVar (&filename, "filename", "shaders/seascape.glsl", "path to GLSL file")
|
flag.StringVar (&filename, "filename", "shaders/seascape.glsl", "path to GLSL file")
|
||||||
flag.IntVar (&width, "width", 1024, "Width of the OpenGL Window")
|
flag.IntVar (&width, "width", 1024, "Width of the OpenGL Window")
|
||||||
flag.IntVar (&height, "height", 768, "Height of the OpenGL Window")
|
flag.IntVar (&height, "height", 768, "Height of the OpenGL Window")
|
||||||
|
var tmp float64
|
||||||
flag.Float64Var (&glDrift, "drift", 0.01, "Speed of the gradual camera drift")
|
flag.Float64Var (&tmp, "drift", 0.01, "Speed of the gradual camera drift")
|
||||||
flag.BoolVar (&race, "race", race, "Use race detector")
|
flag.BoolVar (&race, "race", race, "Use race detector")
|
||||||
|
|
||||||
// Set the output if something fails to stdout rather than stderr
|
// Set the output if something fails to stdout rather than stderr
|
||||||
flag.CommandLine.SetOutput(os.Stdout)
|
flag.CommandLine.SetOutput(os.Stdout)
|
||||||
|
// flag.SetOutput(os.Stdout)
|
||||||
|
|
||||||
flag.Usage = customUsage
|
flag.Usage = customUsage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if flag.Parsed() {
|
if flag.Parsed() {
|
||||||
log.Println("flag.Parse() worked")
|
log.Println("Parsed() worked. width=",width)
|
||||||
} else {
|
} else {
|
||||||
log.Println("flag.Parse() failed")
|
log.Println("Parsed() failed. width=",width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// keys := []string{"filename", "width", "height", "drift"}
|
// if err := flag.Parse(); err != nil {
|
||||||
// keys := []string{"width", "height", "drift"}
|
// log.Println("Example:",width)
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
// keys := []string{"height"}
|
uDrift = float32(tmp)
|
||||||
// config.LoadFlags(keys)
|
log.Println("width=",width)
|
||||||
|
log.Println("height=",height)
|
||||||
config.Set("width", width)
|
log.Println("uDrift=",uDrift)
|
||||||
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"})
|
|
||||||
}
|
}
|
|
@ -10,15 +10,11 @@ import (
|
||||||
"golang.org/x/image/colornames"
|
"golang.org/x/image/colornames"
|
||||||
)
|
)
|
||||||
|
|
||||||
import "log"
|
|
||||||
import "github.com/gookit/config"
|
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
// Set up window configs
|
// Set up window configs
|
||||||
log.Println("width = ", config.Int("width"), "height = ", config.String("height"))
|
|
||||||
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
cfg := pixelgl.WindowConfig{ // Default: 1024 x 768
|
||||||
Title: "Golang GLSL",
|
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,
|
VSync: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +31,7 @@ func run() {
|
||||||
// I am putting all shader example initializing stuff here for
|
// I am putting all shader example initializing stuff here for
|
||||||
// easier reference to those learning to use this functionality
|
// easier reference to those learning to use this functionality
|
||||||
|
|
||||||
log.Println("Load GSGL file = ", config.String("filename"))
|
fragSource, err := LoadFileToString(filename)
|
||||||
fragSource, err := LoadFileToString(config.String("filename"))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -44,8 +39,6 @@ func run() {
|
||||||
|
|
||||||
var uMouse mgl32.Vec4
|
var uMouse mgl32.Vec4
|
||||||
var uTime float32
|
var uTime float32
|
||||||
log.Println("glDrift = ", config.String("glDrift"))
|
|
||||||
var glDrift float32 = float32(config.Float("glDrift"))
|
|
||||||
|
|
||||||
canvas := win.Canvas()
|
canvas := win.Canvas()
|
||||||
uResolution := mgl32.Vec2{float32(win.Bounds().W()), float32(win.Bounds().H())}
|
uResolution := mgl32.Vec2{float32(win.Bounds().W()), float32(win.Bounds().H())}
|
||||||
|
@ -54,7 +47,7 @@ func run() {
|
||||||
"uResolution", &uResolution,
|
"uResolution", &uResolution,
|
||||||
"uTime", &uTime,
|
"uTime", &uTime,
|
||||||
"uMouse", &uMouse,
|
"uMouse", &uMouse,
|
||||||
"uDrift", &glDrift,
|
"uDrift", &uDrift,
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas.SetFragmentShader(fragSource)
|
canvas.SetFragmentShader(fragSource)
|
||||||
|
@ -79,8 +72,7 @@ func run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// This parses the command line arguments
|
parseFlags()
|
||||||
parseConfig()
|
|
||||||
|
|
||||||
pixelgl.Run(run)
|
pixelgl.Run(run)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue