updated glfw and sdl examples
This commit is contained in:
parent
1f682f1f31
commit
041cf94c5c
2 changed files with 12 additions and 10 deletions
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/go-gl/gl/v3.2-core/gl"
|
"github.com/go-gl/gl/v3.2-core/gl"
|
||||||
"github.com/go-gl/glfw/v3.2/glfw"
|
"github.com/go-gl/glfw/v3.2/glfw"
|
||||||
"github.com/tfriedel6/canvas"
|
"github.com/tfriedel6/canvas"
|
||||||
"github.com/tfriedel6/canvas/glimpl/gogl"
|
"github.com/tfriedel6/canvas/backend/gogl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -41,8 +41,8 @@ func main() {
|
||||||
glfw.SwapInterval(1)
|
glfw.SwapInterval(1)
|
||||||
gl.Enable(gl.MULTISAMPLE)
|
gl.Enable(gl.MULTISAMPLE)
|
||||||
|
|
||||||
// load canvas GL assets
|
// load GL backend
|
||||||
err = canvas.LoadGL(glimplgogl.GLImpl{})
|
backend, err := goglbackend.New(0, 0, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error loading canvas GL assets: %v", err)
|
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
|
// 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() {
|
for !window.ShouldClose() {
|
||||||
window.MakeContextCurrent()
|
window.MakeContextCurrent()
|
||||||
|
@ -60,7 +60,7 @@ func main() {
|
||||||
|
|
||||||
// set canvas size
|
// set canvas size
|
||||||
ww, wh := window.GetSize()
|
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
|
// call the run function to do all the drawing
|
||||||
run(cv, float64(ww), float64(wh))
|
run(cv, float64(ww), float64(wh))
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-gl/gl/v3.2-core/gl"
|
"github.com/go-gl/gl/v3.2-core/gl"
|
||||||
"github.com/tfriedel6/canvas"
|
"github.com/tfriedel6/canvas"
|
||||||
"github.com/tfriedel6/canvas/glimpl/gogl"
|
"github.com/tfriedel6/canvas/backend/gogl"
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ func main() {
|
||||||
sdl.GLSetSwapInterval(1)
|
sdl.GLSetSwapInterval(1)
|
||||||
gl.Enable(gl.MULTISAMPLE)
|
gl.Enable(gl.MULTISAMPLE)
|
||||||
|
|
||||||
// load canvas GL assets
|
// load GL backend
|
||||||
err = canvas.LoadGL(glimplgogl.GLImpl{})
|
backend, err := goglbackend.New(0, 0, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error loading canvas GL assets: %v", err)
|
log.Fatalf("Error loading canvas GL assets: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize canvas with zero size, since size is set in main loop
|
// 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; {
|
for running := true; running; {
|
||||||
err := window.GLMakeCurrent(glContext)
|
err := window.GLMakeCurrent(glContext)
|
||||||
|
@ -92,6 +92,8 @@ func main() {
|
||||||
}
|
}
|
||||||
case *sdl.MouseMotionEvent:
|
case *sdl.MouseMotionEvent:
|
||||||
mx, my = float64(e.X), float64(e.Y)
|
mx, my = float64(e.X), float64(e.Y)
|
||||||
|
case *sdl.QuitEvent:
|
||||||
|
running = false
|
||||||
case *sdl.WindowEvent:
|
case *sdl.WindowEvent:
|
||||||
if e.Type == sdl.WINDOWEVENT_CLOSE {
|
if e.Type == sdl.WINDOWEVENT_CLOSE {
|
||||||
running = false
|
running = false
|
||||||
|
@ -101,7 +103,7 @@ func main() {
|
||||||
|
|
||||||
// set canvas size
|
// set canvas size
|
||||||
ww, wh := window.GetSize()
|
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
|
// call the run function to do all the drawing
|
||||||
run(cv, float64(ww), float64(wh))
|
run(cv, float64(ww), float64(wh))
|
||||||
|
|
Loading…
Reference in a new issue