add function for glfw loop

This commit is contained in:
lordwelch 2016-01-25 17:27:00 -08:00
parent 5410aac4d4
commit cf0300fb62

66
main.go
View File

@ -11,7 +11,7 @@ import (
"github.com/go-gl/glfw/v3.1/glfw" "github.com/go-gl/glfw/v3.1/glfw"
"github.com/kardianos/osext" "github.com/kardianos/osext"
"gopkg.in/qml.v1" "github.com/lordwelch/qml"
) )
type cell struct { type cell struct {
@ -27,16 +27,13 @@ var (
textEdit qml.Object textEdit qml.Object
cellQml qml.Object cellQml qml.Object
window *qml.Window window *qml.Window
win *glfw.Window
slides slide slides slide
err error err error
monitors []*glfw.Monitor monitors []*glfw.Monitor
) )
func main() { func main() {
if err := glfw.Init(); err != nil {
log.Fatalln("failed to initialize glfw:", err)
}
checkMon()
if err := qml.Run(run); err != nil { if err := qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err) fmt.Fprintf(os.Stderr, "error: %v\n", err)
@ -52,15 +49,56 @@ func init() {
} }
func run() error { func run() error {
engine := qml.NewEngine() engine := qml.NewEngine()
path, err = osext.ExecutableFolder() path, err = osext.ExecutableFolder()
path = filepath.Clean(path + "/../src/github.com/lordwelch/PresentationApp/") path = filepath.Clean(path + "/../src/github.com/lordwelch/PresentationApp/")
//fmt.Println(path) //fmt.Println(path)
qml.RunMain(func() {
if err = glfw.Init(); err != nil {
log.Fatalln("failed to initialize glfw:", err)
}
checkMon()
win, err = glfw.CreateWindow(800, 600, "Cube", nil, nil)
if err != nil {
panic(err)
}
win.MakeContextCurrent()
fmt.Printf("qml loop: %d\n", qml.Ilyuh)
qml.Ilyuh++
if !win.ShouldClose() {
win.SwapBuffers()
glfw.PollEvents()
}
})
qml.RunMain(func() {
fmt.Println("win: ", win.ShouldClose())
fmt.Printf("qml loop: %d\n", qml.Ilyuh)
qml.Ilyuh++
if !win.ShouldClose() {
win.SwapBuffers()
glfw.PollEvents()
}
})
mainQml, err := engine.LoadFile(path + "/main.qml") mainQml, err := engine.LoadFile(path + "/main.qml")
if err != nil { if err != nil {
return err return err
} }
qml.RunMain(func() {
fmt.Printf("qml loop: %d\n", qml.Ilyuh)
qml.Ilyuh++
if !win.ShouldClose() {
win.SwapBuffers()
glfw.PollEvents()
}
})
/*projQml, err := engine.LoadFile(path + "/qml/projection.qml") /*projQml, err := engine.LoadFile(path + "/qml/projection.qml")
if err != nil { if err != nil {
return err return err
@ -76,6 +114,24 @@ func run() error {
textEdit = window.ObjectByName("textEdit") textEdit = window.ObjectByName("textEdit")
slides.addCell() slides.addCell()
qml.RunMain(func() {
fmt.Printf("qml loop: %d\n", qml.Ilyuh)
qml.Ilyuh++
if !win.ShouldClose() {
win.SwapBuffers()
glfw.PollEvents()
}
})
qml.Ilyuh = 0
qml.Func1 = func() {
fmt.Printf("qml loop: %d\n", qml.Ilyuh)
qml.Ilyuh++
if !win.ShouldClose() {
win.SwapBuffers()
glfw.PollEvents()
}
}
window.Show() window.Show()
window.Wait() window.Wait()
return nil return nil