Compare commits

...

7 Commits

Author SHA1 Message Date
Jeff Carr b0b6e97726 Merge branch 'master' of git.wit.org:jcarr/pixel-examples into github-master 2021-08-30 19:37:46 -05:00
Jeff Carr 1f99b7ee04 junk
Signed-off-by: Jeff Carr <jcarr@wit.com>
2019-01-15 08:37:22 -08:00
Jeff Carr 25c0ba5c87 a bit better code
Signed-off-by: Jeff Carr <jcarr@wit.com>
2019-01-15 08:29:59 -08:00
Jeff Carr aa46ffffe4 remove junk
Signed-off-by: Jeff Carr <jcarr@wit.com>
2019-01-15 08:17:07 -08:00
Jeff Carr 3ad06351ae finally runs 2019-01-15 08:05:59 -08:00
Jeff Carr 9d39c2dbcb print the executable name correctly
Signed-off-by: Jeff Carr <jcarr@wit.com>
2019-01-09 04:30:11 -08:00
Jeff Carr 8f5d223b36 add both examples
Signed-off-by: Jeff Carr <jcarr@wit.com>
2019-01-09 04:19:12 -08:00
2 changed files with 50 additions and 30 deletions

View File

@ -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"})
} }

View File

@ -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)
} }