github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/textinput/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "log" 6 "runtime" 7 8 "github.com/go-gl/gl/v2.1/gl" 9 "github.com/go-gl/glfw/v3.2/glfw" 10 ) 11 12 func init() { runtime.LockOSThread() } 13 14 func main() { 15 flag.Parse() 16 17 if err := glfw.Init(); err != nil { 18 log.Fatalln("failed to initialize glfw:", err) 19 } 20 defer glfw.Terminate() 21 22 glfw.WindowHint(glfw.Resizable, glfw.True) 23 glfw.WindowHint(glfw.Visible, glfw.False) // do not steal focus 24 25 glfw.WindowHint(glfw.ContextVersionMajor, 2) 26 glfw.WindowHint(glfw.ContextVersionMinor, 1) 27 28 glfw.WindowHint(glfw.Samples, 4) 29 30 window, err := glfw.CreateWindow(800, 600, "Editor", nil, nil) 31 if err != nil { 32 panic(err) 33 } 34 window.MakeContextCurrent() 35 window.Restore() // do not steal focus 36 37 window.SetPos(32, 64) 38 39 if err := gl.Init(); err != nil { 40 panic(err) 41 } 42 43 screen := NewScreen() 44 window.SetKeyCallback(screen.KeyCallback) 45 46 for !window.ShouldClose() { 47 screen.Update(window) 48 window.SwapBuffers() 49 glfw.PollEvents() 50 } 51 }