diff --git a/examples/shader/image.go b/examples/shader/image.go index 0c05994bc..0dcd1620d 100644 --- a/examples/shader/image.go +++ b/examples/shader/image.go @@ -16,6 +16,8 @@ package main +var Time float +var Cursor vec2 var Image texture2d func Vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2) { @@ -27,7 +29,7 @@ func Vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2) { ) * vec4(position, 0, 1), texCoord } -func Fragment(position vec4, tex vec2) vec4 { +func Fragment(position vec4, texCoord vec2) vec4 { // TODO: Instead of using texture2D directly, define and use special functions for Ebiten images. - return texture2D(Image, tex) + return texture2D(Image, texCoord) } diff --git a/examples/shader/image_go.go b/examples/shader/image_go.go index 2b7ca81a6..74baac79b 100644 --- a/examples/shader/image_go.go +++ b/examples/shader/image_go.go @@ -3,4 +3,4 @@ package main -var image_go = []byte("// Copyright 2020 The Ebiten Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// +build ignore\n\npackage main\n\nvar Image texture2d\n\nfunc Vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2) {\n\treturn mat4(\n\t\t2/viewportSize().x, 0, 0, 0,\n\t\t0, 2/viewportSize().y, 0, 0,\n\t\t0, 0, 1, 0,\n\t\t-1, -1, 0, 1,\n\t) * vec4(position, 0, 1), texCoord\n}\n\nfunc Fragment(position vec4, tex vec2) vec4 {\n\t// TODO: Instead of using texture2D directly, define and use special functions for Ebiten images.\n\treturn texture2D(Image, tex)\n}\n") +var image_go = []byte("// Copyright 2020 The Ebiten Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// +build ignore\n\npackage main\n\nvar Time float\nvar Cursor vec2\nvar Image texture2d\n\nfunc Vertex(position vec2, texCoord vec2, color vec4) (vec4, vec2) {\n\treturn mat4(\n\t\t2/viewportSize().x, 0, 0, 0,\n\t\t0, 2/viewportSize().y, 0, 0,\n\t\t0, 0, 1, 0,\n\t\t-1, -1, 0, 1,\n\t) * vec4(position, 0, 1), texCoord\n}\n\nfunc Fragment(position vec4, texCoord vec2) vec4 {\n\t// TODO: Instead of using texture2D directly, define and use special functions for Ebiten images.\n\treturn texture2D(Image, texCoord)\n}\n") diff --git a/examples/shader/main.go b/examples/shader/main.go index c28b7ab9f..8f3a7cf1b 100644 --- a/examples/shader/main.go +++ b/examples/shader/main.go @@ -125,16 +125,14 @@ func (g *Game) Draw(screen *ebiten.Image) { cx, cy := ebiten.CursorPosition() op := &ebiten.DrawTrianglesWithShaderOptions{} - switch g.idx { - case 0: - op.Uniforms = []interface{}{ - float32(g.time) / 60, // Time - []float32{float32(cx), float32(cy)}, // Cursor - } - default: - op.Uniforms = []interface{}{ + op.Uniforms = []interface{}{ + float32(g.time) / 60, // Time + []float32{float32(cx), float32(cy)}, // Cursor + } + if g.idx != 0 { + op.Uniforms = append(op.Uniforms, gophersImage, // Image - } + ) } screen.DrawTrianglesWithShader(vs, is, s, op)