103 lines
1.8 KiB
Go
103 lines
1.8 KiB
Go
|
//+build !android
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"os/exec"
|
||
|
"time"
|
||
|
|
||
|
"github.com/go-gl/gl/v3.2-core/gl"
|
||
|
"github.com/go-gl/glfw/v3.2/glfw"
|
||
|
//"github.com/golang-ui/nuklear/nk"
|
||
|
"gitlab.wow.st/gmp/nuklear/nk"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
win *glfw.Window
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
datadir = "./"
|
||
|
fontSize = 24
|
||
|
)
|
||
|
|
||
|
func platformInit() {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func mkWin() {
|
||
|
var err error
|
||
|
if err = glfw.Init(); err != nil {
|
||
|
log(Fatal, err)
|
||
|
}
|
||
|
glfw.WindowHint(glfw.ContextVersionMajor, 3)
|
||
|
glfw.WindowHint(glfw.ContextVersionMinor, 2)
|
||
|
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
|
||
|
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
|
||
|
win, err = glfw.CreateWindow(initWidth, initHeight, "Commute", nil, nil)
|
||
|
if err != nil {
|
||
|
log(Fatal, err)
|
||
|
}
|
||
|
win.MakeContextCurrent()
|
||
|
|
||
|
width, height := win.GetSize()
|
||
|
log(Info, "created window ", width, "x", height)
|
||
|
|
||
|
if err := gl.Init(); err != nil {
|
||
|
log(Fatal,"opengl: init failed: ", err)
|
||
|
}
|
||
|
gl.Viewport(0,0, int32(width), int32(height))
|
||
|
|
||
|
ctx = nk.NkPlatformInit(win, nk.PlatformInstallCallbacks)
|
||
|
|
||
|
loadFont()
|
||
|
}
|
||
|
|
||
|
func Terminate() {
|
||
|
glfw.Terminate()
|
||
|
}
|
||
|
|
||
|
func PollEvents() {
|
||
|
glfw.PollEvents()
|
||
|
}
|
||
|
|
||
|
func GetSize() (width, height int) {
|
||
|
return win.GetSize()
|
||
|
}
|
||
|
|
||
|
func SwapBuffers() {
|
||
|
win.SwapBuffers()
|
||
|
}
|
||
|
|
||
|
func eventloop() {
|
||
|
for {
|
||
|
// if nk.Animate() && lastY != y {
|
||
|
if lastY != y {
|
||
|
glfw.WaitEventsTimeout(float64(1/60))
|
||
|
} else {
|
||
|
time.Sleep(time.Second/60)
|
||
|
glfw.WaitEventsTimeout(float64(1))
|
||
|
}
|
||
|
gfxMain()
|
||
|
glfw.WaitEventsTimeout(float64(1/60))
|
||
|
gfxMain()
|
||
|
if win.ShouldClose() {
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func BackButton(s string) bool {
|
||
|
return button(s)
|
||
|
}
|
||
|
|
||
|
|
||
|
func Clip(x string) {
|
||
|
b := bytes.NewBuffer([]byte(x))
|
||
|
cmd := exec.Command("pbcopy")
|
||
|
cmd.Stdin = b
|
||
|
cmd.Run()
|
||
|
}
|
||
|
|