updated glfw and sdl examples

This commit is contained in:
Thomas Friedel 2019-02-24 11:07:07 +01:00
parent 1f682f1f31
commit 041cf94c5c
2 changed files with 12 additions and 10 deletions

View file

@ -7,7 +7,7 @@ import (
"github.com/go-gl/gl/v3.2-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/glimpl/gogl"
"github.com/tfriedel6/canvas/backend/gogl"
)
func main() {
@ -41,8 +41,8 @@ func main() {
glfw.SwapInterval(1)
gl.Enable(gl.MULTISAMPLE)
// load canvas GL assets
err = canvas.LoadGL(glimplgogl.GLImpl{})
// load GL backend
backend, err := goglbackend.New(0, 0, 0, 0)
if err != nil {
log.Fatalf("Error loading canvas GL assets: %v", err)
}
@ -52,7 +52,7 @@ func main() {
})
// initialize canvas with zero size, since size is set in main loop
cv := canvas.New(0, 0, 0, 0)
cv := canvas.New(backend)
for !window.ShouldClose() {
window.MakeContextCurrent()
@ -60,7 +60,7 @@ func main() {
// set canvas size
ww, wh := window.GetSize()
cv.SetBounds(0, 0, ww, wh)
backend.SetBounds(0, 0, ww, wh)
// call the run function to do all the drawing
run(cv, float64(ww), float64(wh))

View file

@ -7,7 +7,7 @@ import (
"github.com/go-gl/gl/v3.2-core/gl"
"github.com/tfriedel6/canvas"
"github.com/tfriedel6/canvas/glimpl/gogl"
"github.com/tfriedel6/canvas/backend/gogl"
"github.com/veandco/go-sdl2/sdl"
)
@ -62,14 +62,14 @@ func main() {
sdl.GLSetSwapInterval(1)
gl.Enable(gl.MULTISAMPLE)
// load canvas GL assets
err = canvas.LoadGL(glimplgogl.GLImpl{})
// load GL backend
backend, err := goglbackend.New(0, 0, 0, 0)
if err != nil {
log.Fatalf("Error loading canvas GL assets: %v", err)
}
// initialize canvas with zero size, since size is set in main loop
cv := canvas.New(0, 0, 0, 0)
cv := canvas.New(backend)
for running := true; running; {
err := window.GLMakeCurrent(glContext)
@ -92,6 +92,8 @@ func main() {
}
case *sdl.MouseMotionEvent:
mx, my = float64(e.X), float64(e.Y)
case *sdl.QuitEvent:
running = false
case *sdl.WindowEvent:
if e.Type == sdl.WINDOWEVENT_CLOSE {
running = false
@ -101,7 +103,7 @@ func main() {
// set canvas size
ww, wh := window.GetSize()
cv.SetBounds(0, 0, int(ww), int(wh))
backend.SetBounds(0, 0, int(ww), int(wh))
// call the run function to do all the drawing
run(cv, float64(ww), float64(wh))