diff --git a/ebiten.go b/ebiten.go index 3857bde2e..e9e3e64ef 100644 --- a/ebiten.go +++ b/ebiten.go @@ -1,9 +1,9 @@ package ebiten import ( - "time" "github.com/hajimehoshi/go-ebiten/graphics" "github.com/hajimehoshi/go-ebiten/graphics/opengl" + "time" ) type Game interface { @@ -26,7 +26,7 @@ func OpenGLRun(game Game, ui UI) { func(g graphics.GraphicsContext, offscreen graphics.TextureID) { ticket := <-ch game.Draw(g, offscreen) - ch<- ticket + ch <- ticket }) go func() { @@ -36,11 +36,11 @@ func OpenGLRun(game Game, ui UI) { <-tick ticket := <-ch game.Update() - ch<- ticket + ch <- ticket } }() game.Init(device.TextureFactory()) - ch<- true + ch <- true ui.Run(device) } diff --git a/examples/glut/main.go b/examples/glut/main.go index 9e400cf31..3c91f8981 100644 --- a/examples/glut/main.go +++ b/examples/glut/main.go @@ -15,21 +15,21 @@ package main // import "C" import ( + "github.com/hajimehoshi/go-ebiten" + "github.com/hajimehoshi/go-ebiten/graphics" "image" "image/color" _ "image/png" "os" "runtime" "unsafe" - "github.com/hajimehoshi/go-ebiten" - "github.com/hajimehoshi/go-ebiten/graphics" ) -type GlutUI struct{ - screenWidth int +type GlutUI struct { + screenWidth int screenHeight int - screenScale int - device graphics.Device + screenScale int + device graphics.Device } var currentUI *GlutUI @@ -57,15 +57,15 @@ func (ui *GlutUI) Init() { }() cargc := C.int(len(cargs)) - ui.screenWidth = 256 + ui.screenWidth = 256 ui.screenHeight = 240 - ui.screenScale = 2 + ui.screenScale = 2 C.glutInit(&cargc, &cargs[0]) - C.glutInitDisplayMode(C.GLUT_RGBA); + C.glutInitDisplayMode(C.GLUT_RGBA) C.glutInitWindowSize( - C.int(ui.screenWidth * ui.screenScale), - C.int(ui.screenHeight * ui.screenScale)) + C.int(ui.screenWidth*ui.screenScale), + C.int(ui.screenHeight*ui.screenScale)) title := C.CString("Ebiten Demo") defer C.free(unsafe.Pointer(title)) @@ -93,7 +93,7 @@ func (ui *GlutUI) Run(device graphics.Device) { type DemoGame struct { ebitenTexture graphics.Texture - x int + x int } func (game *DemoGame) Init(tf graphics.TextureFactory) { @@ -102,7 +102,7 @@ func (game *DemoGame) Init(tf graphics.TextureFactory) { panic(err) } defer file.Close() - + img, _, err := image.Decode(file) if err != nil { panic(err) diff --git a/graphics/affine_matrix_test.go b/graphics/affine_matrix_test.go index 39a727f30..82bb1edb8 100644 --- a/graphics/affine_matrix_test.go +++ b/graphics/affine_matrix_test.go @@ -1,8 +1,8 @@ package graphics_test import ( - "testing" . "." + "testing" ) func setElements(matrix *AffineMatrix, elements [][]float64) { diff --git a/graphics/geometry_matrix_test.go b/graphics/geometry_matrix_test.go index 45cd7690d..8f737e10f 100644 --- a/graphics/geometry_matrix_test.go +++ b/graphics/geometry_matrix_test.go @@ -1,8 +1,8 @@ package graphics_test import ( - "testing" . "." + "testing" ) func TestGeometryMatrixElements(t *testing.T) { diff --git a/graphics/graphics.go b/graphics/graphics.go index 10dc5ff2b..b0be06b32 100644 --- a/graphics/graphics.go +++ b/graphics/graphics.go @@ -25,8 +25,8 @@ type TextureFactory interface { } type Texture struct { - ID TextureID - Width int + ID TextureID + Width int Height int } diff --git a/graphics/opengl/device.go b/graphics/opengl/device.go index fea10e6b9..e490ad8ff 100644 --- a/graphics/opengl/device.go +++ b/graphics/opengl/device.go @@ -10,22 +10,22 @@ import ( ) type Device struct { - screenWidth int - screenHeight int - screenScale int - graphicsContext *GraphicsContext + screenWidth int + screenHeight int + screenScale int + graphicsContext *GraphicsContext offscreenTexture graphics.Texture - drawFunc func(graphics.GraphicsContext, graphics.TextureID) + drawFunc func(graphics.GraphicsContext, graphics.TextureID) } func NewDevice(screenWidth, screenHeight, screenScale int, drawFunc func(graphics.GraphicsContext, graphics.TextureID)) *Device { device := &Device{ - screenWidth: screenWidth, - screenHeight: screenHeight, - screenScale: screenScale, + screenWidth: screenWidth, + screenHeight: screenHeight, + screenScale: screenScale, graphicsContext: newGraphicsContext(screenWidth, screenHeight, screenScale), - drawFunc: drawFunc, + drawFunc: drawFunc, } device.offscreenTexture = device.graphicsContext.NewTexture(screenWidth, screenHeight) @@ -41,7 +41,7 @@ func (device *Device) Update() { g.Clear() device.drawFunc(g, device.offscreenTexture.ID) g.flush() - + C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) g.resetOffscreen() diff --git a/graphics/opengl/graphics_context.go b/graphics/opengl/graphics_context.go index a5200b6e5..acf770cda 100644 --- a/graphics/opengl/graphics_context.go +++ b/graphics/opengl/graphics_context.go @@ -7,32 +7,32 @@ package opengl import "C" import ( "fmt" + "github.com/hajimehoshi/go-ebiten/graphics" "image" "image/color" "unsafe" - "github.com/hajimehoshi/go-ebiten/graphics" ) type GraphicsContext struct { - screenWidth int - screenHeight int - screenScale int - textures map[graphics.TextureID]*Texture - projectionMatrix [16]float32 + screenWidth int + screenHeight int + screenScale int + textures map[graphics.TextureID]*Texture + projectionMatrix [16]float32 currentShaderProgram C.GLuint - mainFramebuffer C.GLuint - framebuffers map[C.GLuint]C.GLuint + mainFramebuffer C.GLuint + framebuffers map[C.GLuint]C.GLuint } // This method should be called on the UI thread. func newGraphicsContext(screenWidth, screenHeight, screenScale int) *GraphicsContext { context := &GraphicsContext{ - screenWidth: screenWidth, - screenHeight: screenHeight, - screenScale: screenScale, - textures: map[graphics.TextureID]*Texture{}, + screenWidth: screenWidth, + screenHeight: screenHeight, + screenScale: screenScale, + textures: map[graphics.TextureID]*Texture{}, mainFramebuffer: 0, - framebuffers: map[C.GLuint]C.GLuint{}, + framebuffers: map[C.GLuint]C.GLuint{}, } // main framebuffer should be created sooner than any other framebuffers! mainFramebuffer := C.GLint(0) @@ -53,10 +53,10 @@ func (context *GraphicsContext) Fill(clr color.Color) { r, g, b, a := clr.RGBA() max := 65535.0 C.glClearColor( - C.GLclampf(float64(r) / max), - C.GLclampf(float64(g) / max), - C.GLclampf(float64(b) / max), - C.GLclampf(float64(a) / max)) + C.GLclampf(float64(r)/max), + C.GLclampf(float64(g)/max), + C.GLclampf(float64(b)/max), + C.GLclampf(float64(a)/max)) C.glClear(C.GL_COLOR_BUFFER_BIT) } @@ -69,7 +69,7 @@ func (context *GraphicsContext) DrawTexture( srcX, srcY, srcWidth, srcHeight int, geometryMatrix *graphics.GeometryMatrix, colorMatrix *graphics.ColorMatrix) { geometryMatrix = geometryMatrix.Clone() - colorMatrix = colorMatrix.Clone() + colorMatrix = colorMatrix.Clone() texture := context.textures[textureID] @@ -87,10 +87,10 @@ func (context *GraphicsContext) DrawTexture( x2, y2, } - tu1 := float32(srcX) / float32(texture.textureWidth) - tu2 := float32(srcX + srcWidth) / float32(texture.textureWidth) - tv1 := float32(srcY) / float32(texture.textureHeight) - tv2 := float32(srcY + srcHeight) / float32(texture.textureHeight) + tu1 := float32(srcX) / float32(texture.textureWidth) + tu2 := float32(srcX+srcWidth) / float32(texture.textureWidth) + tv1 := float32(srcY) / float32(texture.textureHeight) + tv2 := float32(srcY+srcHeight) / float32(texture.textureHeight) texCoord := [...]float32{ tu1, tv1, tu2, tv1, @@ -138,8 +138,7 @@ func (context *GraphicsContext) setOffscreenFramebuffer(framebuffer C.GLuint, C.glFlush() C.glBindFramebuffer(C.GL_FRAMEBUFFER, framebuffer) - if err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER); - err != C.GL_FRAMEBUFFER_COMPLETE { + if err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER); err != C.GL_FRAMEBUFFER_COMPLETE { panic(fmt.Sprintf("glBindFramebuffer failed: %d", err)) } C.glEnable(C.GL_BLEND) @@ -147,15 +146,15 @@ func (context *GraphicsContext) setOffscreenFramebuffer(framebuffer C.GLuint, width, height, tx, ty := 0, 0, 0, 0 if framebuffer != context.mainFramebuffer { - width = textureWidth + width = textureWidth height = textureHeight - tx = -1 - ty = -1 + tx = -1 + ty = -1 } else { - width = context.screenWidth * context.screenScale + width = context.screenWidth * context.screenScale height = -1 * context.screenHeight * context.screenScale - tx = -1 - ty = 1 + tx = -1 + ty = 1 } C.glViewport(0, 0, C.GLsizei(abs(width)), C.GLsizei(abs(height))) e11 := float32(2.0) / float32(width) @@ -163,9 +162,9 @@ func (context *GraphicsContext) setOffscreenFramebuffer(framebuffer C.GLuint, e41 := float32(tx) e42 := float32(ty) context.projectionMatrix = [...]float32{ - e11, 0, 0, 0, - 0, e22, 0, 0, - 0, 0, 1, 0, + e11, 0, 0, 0, + 0, e22, 0, 0, + 0, 0, 1, 0, e41, e42, 0, 1, } } @@ -196,16 +195,16 @@ func (context *GraphicsContext) setShaderProgram( 1, C.GL_FALSE, (*C.GLfloat)(&context.projectionMatrix[0])) - a := float32(geometryMatrix.A()) - b := float32(geometryMatrix.B()) - c := float32(geometryMatrix.C()) - d := float32(geometryMatrix.D()) + a := float32(geometryMatrix.A()) + b := float32(geometryMatrix.B()) + c := float32(geometryMatrix.C()) + d := float32(geometryMatrix.D()) tx := float32(geometryMatrix.Tx()) ty := float32(geometryMatrix.Ty()) glModelviewMatrix := [...]float32{ - a, c, 0, 0, - b, d, 0, 0, - 0, 0, 1, 0, + a, c, 0, 0, + b, d, 0, 0, + 0, 0, 1, 0, tx, ty, 0, 1, } C.glUniformMatrix4fv(getUniformLocation(program, "modelview_matrix"), @@ -241,7 +240,7 @@ func (context *GraphicsContext) setShaderProgram( 1, (*C.GLfloat)(&glColorMatrixTranslation[0])) } -func (context *GraphicsContext) getFramebuffer(textureID C.GLuint) C.GLuint{ +func (context *GraphicsContext) getFramebuffer(textureID C.GLuint) C.GLuint { framebuffer, ok := context.framebuffers[textureID] if ok { return framebuffer diff --git a/graphics/opengl/shader.go b/graphics/opengl/shader.go index 23912d1eb..323ec3c5b 100644 --- a/graphics/opengl/shader.go +++ b/graphics/opengl/shader.go @@ -10,14 +10,14 @@ import ( ) type shader struct { - id C.GLuint - name string + id C.GLuint + name string source string } var ( vertexShader = &shader{ - id: 0, + id: 0, name: "vertex_shader", source: ` attribute /*highp*/ vec2 vertex; @@ -33,7 +33,7 @@ void main(void) { `, } fragmentShader = &shader{ - id: 0, + id: 0, name: "fragment_shader", source: ` uniform /*lowp*/ sampler2D texture; @@ -45,7 +45,7 @@ void main(void) { `, } colorMatrixShader = &shader{ - id: 0, + id: 0, name: "color_matrix_shader", source: ` uniform /*highp*/ sampler2D texture; @@ -62,7 +62,7 @@ void main(void) { ) var ( - regularShaderProgram = C.GLuint(0) + regularShaderProgram = C.GLuint(0) colorMatrixShaderProgram = C.GLuint(0) ) diff --git a/graphics/opengl/texture.go b/graphics/opengl/texture.go index ccc42bea9..2d6045ae2 100644 --- a/graphics/opengl/texture.go +++ b/graphics/opengl/texture.go @@ -21,15 +21,15 @@ func Clp2(x uint64) uint64 { } type Texture struct { - id C.GLuint - width int - height int - textureWidth int + id C.GLuint + width int + height int + textureWidth int textureHeight int } func createTexture(width, height int, pixels []uint8) *Texture { - textureWidth := int(Clp2(uint64(width))) + textureWidth := int(Clp2(uint64(width))) textureHeight := int(Clp2(uint64(height))) if pixels != nil { if width != textureWidth { @@ -40,10 +40,10 @@ func createTexture(width, height int, pixels []uint8) *Texture { } } texture := &Texture{ - id: 0, - width: width, - height: height, - textureWidth: textureWidth, + id: 0, + width: width, + height: height, + textureWidth: textureWidth, textureHeight: textureHeight, } @@ -54,7 +54,7 @@ func createTexture(width, height int, pixels []uint8) *Texture { } C.glPixelStorei(C.GL_UNPACK_ALIGNMENT, 4) C.glBindTexture(C.GL_TEXTURE_2D, C.GLuint(textureID)) - + ptr := unsafe.Pointer(nil) if pixels != nil { ptr = unsafe.Pointer(&pixels[0]) diff --git a/graphics/opengl/texture_test.go b/graphics/opengl/texture_test.go index 13b64a156..a2f0e6629 100644 --- a/graphics/opengl/texture_test.go +++ b/graphics/opengl/texture_test.go @@ -1,14 +1,14 @@ package opengl_test import ( - "testing" . "." + "testing" ) func TestClp2(t *testing.T) { testCases := []struct { expected uint64 - arg uint64 + arg uint64 }{ {256, 255}, {256, 256}, @@ -22,6 +22,6 @@ func TestClp2(t *testing.T) { t.Errorf("Clp(%d) = %d, wanted %d", testCase.arg, got, wanted) } - + } }