Loading main.go 0 → 100644 +36 −0 Original line number Diff line number Diff line package main import ( "fmt" "runtime" "repositories.muehmer.net/bsmrgo/saola/support/scene" si "repositories.muehmer.net/bsmrgo/graphics-playground/scenes/icosahedron" ) func init() { // This is needed to arrange that main() runs on main thread. // See documentation for functions that are only allowed to be called from the main thread. runtime.LockOSThread() } const ( programName = "Graphics Playground" defaultWidth = 1650 defaultHeight = 1080 ) func main() { fmt.Printf("Welcome to the %s!\n", programName) setup := scene.WindowSetup{ Width: defaultWidth, Height: defaultHeight, Title: programName, ContextVersionMajor: 4, ContextVersionMinor: 3, CenterOnPrimaryMonitor: true, } hooks := si.Hooks() scene.Manage(setup, hooks) } scenes/icosahedron/icosahedron.go 0 → 100644 +62 −0 Original line number Diff line number Diff line package icosahedron import ( "fmt" "os" "github.com/go-gl/gl/v4.3-core/gl" "github.com/go-gl/glfw/v3.2/glfw" "repositories.muehmer.net/bsmrgo/saola/support/scene" ) const ( sceneName = "Icosahedron" ) // Hooks returns our hooks. func Hooks() scene.HooksType { hooks := scene.HooksType{ Initialize: initialize, Render: render, Resize: resize, Key: keyCallback, MouseButton: mouseButtonCallback, JoystickAxis: joystickAxisCallback, JoystickButton: joystickButtonCallback, } return hooks } // Initialize the environment. func initialize() { fmt.Fprintf(os.Stderr, "[%s] Initialize()\n", sceneName) } // Resize changes the view. func resize(width, height int) { fmt.Fprintf(os.Stderr, "[%s] Resize(%d, %d)\n", sceneName, width, height) } // Render something. func render() { gl.Clear(gl.COLOR_BUFFER_BIT) } func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { fmt.Fprintf(os.Stderr, "[%s] key: %v - scancode: %d - action: %v - mode: %v\n", sceneName, key, scancode, action, mods) if key == glfw.KeyEscape && action == glfw.Press { w.SetShouldClose(true) } } func mouseButtonCallback(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) { fmt.Fprintf(os.Stderr, "[%s] mouse button: %v - action: %v - mode: %v\n", sceneName, button, action, mod) } func joystickAxisCallback(js glfw.Joystick, axis int, old float32, new float32) { fmt.Fprintf(os.Stderr, "[%s] joystick %v axis %d changed: from %f to %f\n", sceneName, js, axis, old, new) } func joystickButtonCallback(js glfw.Joystick, button int, old byte, new byte) { fmt.Fprintf(os.Stderr, "[%s] joysitck %v button %d changed from %d to %d\n", sceneName, js, button, old, new) } Loading
main.go 0 → 100644 +36 −0 Original line number Diff line number Diff line package main import ( "fmt" "runtime" "repositories.muehmer.net/bsmrgo/saola/support/scene" si "repositories.muehmer.net/bsmrgo/graphics-playground/scenes/icosahedron" ) func init() { // This is needed to arrange that main() runs on main thread. // See documentation for functions that are only allowed to be called from the main thread. runtime.LockOSThread() } const ( programName = "Graphics Playground" defaultWidth = 1650 defaultHeight = 1080 ) func main() { fmt.Printf("Welcome to the %s!\n", programName) setup := scene.WindowSetup{ Width: defaultWidth, Height: defaultHeight, Title: programName, ContextVersionMajor: 4, ContextVersionMinor: 3, CenterOnPrimaryMonitor: true, } hooks := si.Hooks() scene.Manage(setup, hooks) }
scenes/icosahedron/icosahedron.go 0 → 100644 +62 −0 Original line number Diff line number Diff line package icosahedron import ( "fmt" "os" "github.com/go-gl/gl/v4.3-core/gl" "github.com/go-gl/glfw/v3.2/glfw" "repositories.muehmer.net/bsmrgo/saola/support/scene" ) const ( sceneName = "Icosahedron" ) // Hooks returns our hooks. func Hooks() scene.HooksType { hooks := scene.HooksType{ Initialize: initialize, Render: render, Resize: resize, Key: keyCallback, MouseButton: mouseButtonCallback, JoystickAxis: joystickAxisCallback, JoystickButton: joystickButtonCallback, } return hooks } // Initialize the environment. func initialize() { fmt.Fprintf(os.Stderr, "[%s] Initialize()\n", sceneName) } // Resize changes the view. func resize(width, height int) { fmt.Fprintf(os.Stderr, "[%s] Resize(%d, %d)\n", sceneName, width, height) } // Render something. func render() { gl.Clear(gl.COLOR_BUFFER_BIT) } func keyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { fmt.Fprintf(os.Stderr, "[%s] key: %v - scancode: %d - action: %v - mode: %v\n", sceneName, key, scancode, action, mods) if key == glfw.KeyEscape && action == glfw.Press { w.SetShouldClose(true) } } func mouseButtonCallback(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) { fmt.Fprintf(os.Stderr, "[%s] mouse button: %v - action: %v - mode: %v\n", sceneName, button, action, mod) } func joystickAxisCallback(js glfw.Joystick, axis int, old float32, new float32) { fmt.Fprintf(os.Stderr, "[%s] joystick %v axis %d changed: from %f to %f\n", sceneName, js, axis, old, new) } func joystickButtonCallback(js glfw.Joystick, button int, old byte, new byte) { fmt.Fprintf(os.Stderr, "[%s] joysitck %v button %d changed from %d to %d\n", sceneName, js, button, old, new) }