2018-12-27 21:36:34 +00:00
|
|
|
package platform
|
|
|
|
|
|
|
|
import "github.com/veandco/go-sdl2/sdl"
|
|
|
|
|
|
|
|
type Window interface {
|
|
|
|
Destroy() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type window struct {
|
|
|
|
sdlWindow *sdl.Window
|
|
|
|
sdlGlContext sdl.GLContext
|
2018-12-27 21:59:19 +00:00
|
|
|
sdlRenderer *sdl.Renderer
|
2018-12-27 21:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newWindow(title string, width, height int) (Window, error) {
|
|
|
|
sdlWindow, err := sdl.CreateWindow(
|
|
|
|
title,
|
|
|
|
sdl.WINDOWPOS_CENTERED,
|
|
|
|
sdl.WINDOWPOS_CENTERED,
|
|
|
|
int32(width),
|
|
|
|
int32(height),
|
|
|
|
sdl.WINDOW_OPENGL,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sdlGlContext, err := sdlWindow.GLCreateContext()
|
|
|
|
if err != nil {
|
|
|
|
sdlWindow.Destroy()
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-12-27 21:59:19 +00:00
|
|
|
sdlRenderer, err := sdl.CreateRenderer(sdlWindow, -1, sdl.RENDERER_ACCELERATED)
|
|
|
|
if err != nil {
|
|
|
|
sdlWindow.Destroy()
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &window{sdlWindow, sdlGlContext, sdlRenderer}, nil
|
2018-12-27 21:36:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *window) Destroy() error {
|
|
|
|
if w.sdlWindow != nil {
|
|
|
|
if err := w.sdlWindow.Destroy(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.sdlGlContext = nil
|
|
|
|
w.sdlWindow = nil
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|