diff --git a/example/blocks/textures.go b/example/blocks/textures.go index 9d06bede3..38e4ccf4d 100644 --- a/example/blocks/textures.go +++ b/example/blocks/textures.go @@ -34,7 +34,11 @@ func NewTextures(textureFactory graphics.TextureFactory) *Textures { textures: map[string]graphics.TextureId{}, renderTargets: map[string]graphics.RenderTargetId{}, } - go textures.loop() + go func() { + for { + textures.loopMain() + } + }() return textures } @@ -52,43 +56,41 @@ func loadImage(path string) (image.Image, error) { return img, nil } -func (t *Textures) loop() { - for { - select { - case p := <-t.texturePaths: - name := p.name - path := p.path - go func() { - img, err := loadImage(path) - if err != nil { - panic(err) - } - id, err := t.textureFactory.CreateTexture( - img, - graphics.FilterNearest) - if err != nil { - panic(err) - } - t.Lock() - defer t.Unlock() - t.textures[name] = id - }() - case s := <-t.renderTargetSizes: - name := s.name - size := s.size - go func() { - id, err := t.textureFactory.CreateRenderTarget( - size.Width, - size.Height, - graphics.FilterNearest) - if err != nil { - panic(err) - } - t.Lock() - defer t.Unlock() - t.renderTargets[name] = id - }() - } +func (t *Textures) loopMain() { + select { + case p := <-t.texturePaths: + name := p.name + path := p.path + go func() { + img, err := loadImage(path) + if err != nil { + panic(err) + } + id, err := t.textureFactory.CreateTexture( + img, + graphics.FilterNearest) + if err != nil { + panic(err) + } + t.Lock() + defer t.Unlock() + t.textures[name] = id + }() + case s := <-t.renderTargetSizes: + name := s.name + size := s.size + go func() { + id, err := t.textureFactory.CreateRenderTarget( + size.Width, + size.Height, + graphics.FilterNearest) + if err != nil { + panic(err) + } + t.Lock() + defer t.Unlock() + t.renderTargets[name] = id + }() } } diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 1f38fb359..5214d3a6e 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -5,6 +5,21 @@ import ( "github.com/hajimehoshi/go-ebiten/graphics/matrix" ) +// #cgo LDFLAGS: -framework OpenGL +// +// #include +// #include +import "C" + +func enableAlphaBlending() { + C.glEnable(C.GL_TEXTURE_2D) + C.glEnable(C.GL_BLEND) +} + +func flush() { + C.glFlush() +} + type Context struct { screenId graphics.RenderTargetId mainId graphics.RenderTargetId diff --git a/graphics/opengl/gl.go b/graphics/opengl/gl.go deleted file mode 100644 index 12b745eb4..000000000 --- a/graphics/opengl/gl.go +++ /dev/null @@ -1,16 +0,0 @@ -package opengl - -// #cgo LDFLAGS: -framework OpenGL -// -// #include -// #include -import "C" - -func enableAlphaBlending() { - C.glEnable(C.GL_TEXTURE_2D) - C.glEnable(C.GL_BLEND) -} - -func flush() { - C.glFlush() -}