diff --git a/example/blocks/game.go b/example/blocks/game.go index 4edfd3018..317f11081 100644 --- a/example/blocks/game.go +++ b/example/blocks/game.go @@ -2,7 +2,6 @@ package blocks import ( "github.com/hajimehoshi/ebiten/graphics" - _ "image/png" "sync" ) diff --git a/example/blocks/textures.go b/example/blocks/textures.go index eb9b95d69..dd7697a95 100644 --- a/example/blocks/textures.go +++ b/example/blocks/textures.go @@ -3,6 +3,7 @@ package blocks import ( "github.com/hajimehoshi/ebiten/graphics" "image" + _ "image/png" "os" "sync" ) diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 4fc3ce84c..8ddfc5d3e 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -46,7 +46,7 @@ func NewContext(screenWidth, screenHeight, screenScale int) *Context { var err error context.screenId, err = idsInstance.createRenderTarget(screenWidth, screenHeight, graphics.FilterNearest) if err != nil { - panic("initializing the offscreen failed: " + err.Error()) + panic("opengl.NewContext: initializing the offscreen failed: " + err.Error()) } context.ResetOffscreen() context.Clear() diff --git a/graphics/opengl/ids.go b/graphics/opengl/ids.go index 7fe66ed59..6fb0a5409 100644 --- a/graphics/opengl/ids.go +++ b/graphics/opengl/ids.go @@ -10,16 +10,6 @@ import ( "sync" ) -func glMatrix(matrix [4][4]float64) [16]float32 { - result := [16]float32{} - for j := 0; j < 4; j++ { - for i := 0; i < 4; i++ { - result[i+j*4] = float32(matrix[i][j]) - } - } - return result -} - type ids struct { textures map[graphics.TextureID]*Texture renderTargets map[graphics.RenderTargetID]*RenderTarget @@ -36,15 +26,11 @@ var idsInstance = &ids{ currentRenderTargetId: -1, } -func CreateRenderTarget( - width, height int, - filter graphics.Filter) (graphics.RenderTargetID, error) { +func CreateRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) { return idsInstance.createRenderTarget(width, height, filter) } -func CreateTexture( - img image.Image, - filter graphics.Filter) (graphics.TextureID, error) { +func CreateTexture(img image.Image, filter graphics.Filter) (graphics.TextureID, error) { return idsInstance.createTexture(img, filter) } @@ -153,7 +139,7 @@ func (i *ids) drawTexture( r := i.renderTargetAt(target) projectionMatrix := r.projectionMatrix() quads := graphics.TextureQuads(parts, texture.width, texture.height) - shader.DrawTexture(texture.native, glMatrix(projectionMatrix), quads, geo, color) + shader.DrawTexture(texture.native, projectionMatrix, quads, geo, color) } func (i *ids) setViewportIfNeeded(id graphics.RenderTargetID) { diff --git a/graphics/opengl/internal/shader/drawtexture.go b/graphics/opengl/internal/shader/drawtexture.go index 9e0694021..d36989cab 100644 --- a/graphics/opengl/internal/shader/drawtexture.go +++ b/graphics/opengl/internal/shader/drawtexture.go @@ -7,9 +7,19 @@ import ( "sync" ) +func glMatrix(matrix [4][4]float64) [16]float32 { + result := [16]float32{} + for j := 0; j < 4; j++ { + for i := 0; i < 4; i++ { + result[i+j*4] = float32(matrix[i][j]) + } + } + return result +} + var once sync.Once -func DrawTexture(native gl.Texture, projectionMatrix [16]float32, quads []graphics.TextureQuad, geo matrix.Geometry, color matrix.Color) { +func DrawTexture(native gl.Texture, projectionMatrix [4][4]float64, quads []graphics.TextureQuad, geo matrix.Geometry, color matrix.Color) { once.Do(func() { initialize() }) @@ -18,7 +28,7 @@ func DrawTexture(native gl.Texture, projectionMatrix [16]float32, quads []graphi return } // TODO: Check performance - shaderProgram := use(projectionMatrix, geo, color) + shaderProgram := use(glMatrix(projectionMatrix), geo, color) native.Bind(gl.TEXTURE_2D) defer gl.Texture(0).Bind(gl.TEXTURE_2D) diff --git a/ui/glfw/ui.go b/ui/glfw/ui.go index b73f326f8..e2346f3aa 100644 --- a/ui/glfw/ui.go +++ b/ui/glfw/ui.go @@ -19,7 +19,6 @@ type UI struct { func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, error) { if !glfw.Init() { - // TODO: Use glfw error return nil, errors.New("glfw.Init() fails") } glfw.WindowHint(glfw.Resizable, glfw.False)