commit 1946c83caabba19bbc5409e72e66c391b5f0802a
parent 9b4b3e71ac8ec7c6a4d3b52944d0739155182460
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 23 Oct 2024 11:31:57 +0900
complete exercises in getting-started/textures
Diffstat:
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/cmd/sample/fragment.glsl b/cmd/sample/fragment.glsl
@@ -3,8 +3,9 @@ in vec3 vcol;
in vec2 texCoord;
uniform sampler2D texture1;
uniform sampler2D texture2;
+uniform float alpha;
out vec4 fcol;
void main() {
- fcol = mix(texture(texture1, texCoord), texture(texture2, texCoord), 0.2);
+ fcol = mix(texture(texture1, texCoord), texture(texture2, texCoord), alpha);
}
diff --git a/cmd/sample/main.go b/cmd/sample/main.go
@@ -32,6 +32,18 @@ func processInput(w *glfw.Window) {
if w.GetKey(glfw.KeyQ) == glfw.Press {
w.SetShouldClose(true)
}
+ if w.GetKey(glfw.KeyUp) == glfw.Press {
+ alpha += 0.01
+ if alpha > 1.0 {
+ alpha = 1.0
+ }
+ }
+ if w.GetKey(glfw.KeyDown) == glfw.Press {
+ alpha -= 0.01
+ if alpha < 0 {
+ alpha = 0
+ }
+ }
}
var object = draw.Object{
@@ -59,6 +71,8 @@ var object = draw.Object{
},
}
+var alpha float32 = 0.2
+
func main() {
err := glfw.Init()
if err != nil {
@@ -121,6 +135,7 @@ func main() {
processInput(window)
gl.ClearColor(0.2, 0.3, 0.3, 1.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
+ shader.SetFloat32("alpha", alpha)
gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil)
window.SwapBuffers()
glfw.PollEvents()
diff --git a/texture.go b/texture.go
@@ -41,7 +41,7 @@ func NewTextureFlip(name string, v bool, h bool) (*Texture, error) {
gl.BindTexture(gl.TEXTURE_2D, id)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT)
- gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)
+ gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
img, err := loadImage(name)
if err != nil {