moving window to platform

This commit is contained in:
Alex Yatskov 2018-12-27 13:59:19 -08:00
parent 8c0c4890cb
commit c045e345d2
2 changed files with 8 additions and 35 deletions

View File

@ -1,34 +0,0 @@
package graphics
import "github.com/veandco/go-sdl2/sdl"
type Window struct {
window *sdl.Window
renderer *sdl.Renderer
}
func NewWindow(title string, width, height int) (*Window, error) {
window, err := sdl.CreateWindow(
title,
sdl.WINDOWPOS_UNDEFINED,
sdl.WINDOWPOS_UNDEFINED,
int32(width),
int32(height),
sdl.WINDOW_SHOWN,
)
if err != nil {
return nil, err
}
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
window.Destroy()
return nil, err
}
return &Window{window, renderer}, nil
}
func (w *Window) Destroy() {
}

View File

@ -9,6 +9,7 @@ type Window interface {
type window struct {
sdlWindow *sdl.Window
sdlGlContext sdl.GLContext
sdlRenderer *sdl.Renderer
}
func newWindow(title string, width, height int) (Window, error) {
@ -30,7 +31,13 @@ func newWindow(title string, width, height int) (Window, error) {
return nil, err
}
return &window{sdlWindow, sdlGlContext}, nil
sdlRenderer, err := sdl.CreateRenderer(sdlWindow, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
sdlWindow.Destroy()
return nil, err
}
return &window{sdlWindow, sdlGlContext, sdlRenderer}, nil
}
func (w *window) Destroy() error {