Compare commits
7 Commits
93f9cd5359
...
b0b6e97726
Author | SHA1 | Date |
---|---|---|
|
b0b6e97726 | |
|
1f99b7ee04 | |
|
25c0ba5c87 | |
|
aa46ffffe4 | |
|
3ad06351ae | |
|
9d39c2dbcb | |
|
8f5d223b36 |
|
@ -4,64 +4,76 @@ 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("EXAMPLE:")
|
fmt.Println("EXAMPLES:")
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println("seascape-shader --width 640 --height 480 --filename shaders/planetfall.glsl")
|
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("")
|
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 (&tmp, "drift", 0.01, "Speed of the gradual camera drift")
|
flag.Float64Var (&glDrift, "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("Parsed() worked. width=",width)
|
log.Println("flag.Parse() worked")
|
||||||
} else {
|
} else {
|
||||||
log.Println("Parsed() failed. width=",width)
|
log.Println("flag.Parse() failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// if err := flag.Parse(); err != nil {
|
// keys := []string{"filename", "width", "height", "drift"}
|
||||||
// log.Println("Example:",width)
|
// keys := []string{"width", "height", "drift"}
|
||||||
// }
|
|
||||||
|
|
||||||
|
// keys := []string{"height"}
|
||||||
|
// config.LoadFlags(keys)
|
||||||
|
|
||||||
uDrift = float32(tmp)
|
config.Set("width", width)
|
||||||
log.Println("width=",width)
|
config.Set("height", height)
|
||||||
log.Println("height=",height)
|
config.Set("glDrift", glDrift)
|
||||||
log.Println("uDrift=",uDrift)
|
config.Set("filename", filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseConfig() {
|
||||||
|
config.WithOptions(config.ParseEnv)
|
||||||
|
parseFlags()
|
||||||
|
|
||||||
|
config.LoadOSEnv([]string{"MAIL"})
|
||||||
|
config.LoadOSEnv([]string{"USER"})
|
||||||
|
config.LoadOSEnv([]string{"BUILDDEBUG"})
|
||||||
}
|
}
|
|
@ -10,11 +10,15 @@ 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, float64(width), float64(height)),
|
Bounds: pixel.R(0, 0, config.Float("width"), config.Float("height")),
|
||||||
VSync: true,
|
VSync: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +35,8 @@ 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
|
||||||
|
|
||||||
fragSource, err := LoadFileToString(filename)
|
log.Println("Load GSGL file = ", config.String("filename"))
|
||||||
|
fragSource, err := LoadFileToString(config.String("filename"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -39,6 +44,8 @@ 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())}
|
||||||
|
@ -47,7 +54,7 @@ func run() {
|
||||||
"uResolution", &uResolution,
|
"uResolution", &uResolution,
|
||||||
"uTime", &uTime,
|
"uTime", &uTime,
|
||||||
"uMouse", &uMouse,
|
"uMouse", &uMouse,
|
||||||
"uDrift", &uDrift,
|
"uDrift", &glDrift,
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas.SetFragmentShader(fragSource)
|
canvas.SetFragmentShader(fragSource)
|
||||||
|
@ -72,7 +79,8 @@ func run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
parseFlags()
|
// This parses the command line arguments
|
||||||
|
parseConfig()
|
||||||
|
|
||||||
pixelgl.Run(run)
|
pixelgl.Run(run)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue