updated glfwcanvas to use gl backend, fixed error handling
This commit is contained in:
parent
2717a0bdd9
commit
122488e64c
2 changed files with 11 additions and 17 deletions
|
@ -5,7 +5,6 @@ import (
|
||||||
_ "image/gif" // Imported here so that applications based on this package support these formats by default
|
_ "image/gif" // Imported here so that applications based on this package support these formats by default
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
@ -13,7 +12,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"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Window represents the opened window with GL context. The Mouse* and Key*
|
// Window represents the opened window with GL context. The Mouse* and Key*
|
||||||
|
@ -43,7 +42,7 @@ func CreateWindow(w, h int, title string) (*Window, *canvas.Canvas, error) {
|
||||||
// init GLFW
|
// init GLFW
|
||||||
err := glfw.Init()
|
err := glfw.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error initializing GLFW: %v", err)
|
return nil, nil, fmt.Errorf("Error initializing GLFW: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the stencil size setting is required for the canvas to work
|
// the stencil size setting is required for the canvas to work
|
||||||
|
@ -53,32 +52,27 @@ func CreateWindow(w, h int, title string) (*Window, *canvas.Canvas, error) {
|
||||||
// create window
|
// create window
|
||||||
window, err := glfw.CreateWindow(w, h, title, nil, nil)
|
window, err := glfw.CreateWindow(w, h, title, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error creating window: %v", err)
|
return nil, nil, fmt.Errorf("Error creating window: %v", err)
|
||||||
}
|
}
|
||||||
window.MakeContextCurrent()
|
window.MakeContextCurrent()
|
||||||
|
|
||||||
// init GL
|
// init GL
|
||||||
err = gl.Init()
|
err = gl.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error initializing GL: %v", err)
|
return nil, nil, fmt.Errorf("Error initializing GL: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set vsync on, enable multisample (if available)
|
// set vsync on, enable multisample (if available)
|
||||||
glfw.SwapInterval(1)
|
glfw.SwapInterval(1)
|
||||||
gl.Enable(gl.MULTISAMPLE)
|
gl.Enable(gl.MULTISAMPLE)
|
||||||
|
|
||||||
// load canvas GL assets
|
// load canvas GL backend
|
||||||
err = canvas.LoadGL(glimplgogl.GLImpl{})
|
backend, err := goglbackend.New(0, 0, w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error loading canvas GL assets: %v", err)
|
return nil, nil, fmt.Errorf("Error loading GoGL backend: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = canvas.LoadGL(glimplgogl.GLImpl{})
|
cv := canvas.New(backend)
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("Error loading canvas GL assets: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cv := canvas.New(0, 0, w, h)
|
|
||||||
wnd := &Window{
|
wnd := &Window{
|
||||||
Window: window,
|
Window: window,
|
||||||
canvas: cv,
|
canvas: cv,
|
||||||
|
@ -120,7 +114,7 @@ func CreateWindow(w, h int, title string) (*Window, *canvas.Canvas, error) {
|
||||||
if wnd.SizeChange != nil {
|
if wnd.SizeChange != nil {
|
||||||
wnd.SizeChange(width, height)
|
wnd.SizeChange(width, height)
|
||||||
} else {
|
} else {
|
||||||
cv.SetBounds(0, 0, width, height)
|
backend.SetBounds(0, 0, width, height)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
window.SetCloseCallback(func(w *glfw.Window) {
|
window.SetCloseCallback(func(w *glfw.Window) {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
_ "image/gif" // Imported here so that applications based on this package support these formats by default
|
_ "image/gif" // Imported here so that applications based on this package support these formats by default
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"log"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
@ -88,9 +87,10 @@ func CreateWindow(w, h int, title string) (*Window, *canvas.Canvas, error) {
|
||||||
return nil, nil, fmt.Errorf("Error initializing GL: %v", err)
|
return nil, nil, fmt.Errorf("Error initializing GL: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load canvas GL backend
|
||||||
backend, err := goglbackend.New(0, 0, w, h)
|
backend, err := goglbackend.New(0, 0, w, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error loading GoGL backend: %v", err)
|
return nil, nil, fmt.Errorf("Error loading GoGL backend: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sdl.GLSetSwapInterval(1)
|
sdl.GLSetSwapInterval(1)
|
||||||
|
|
Loading…
Reference in a new issue