From 76dfca79570ae1f4dc058ced03f48980466ef777 Mon Sep 17 00:00:00 2001 From: iurii plugatarov Date: Fri, 16 Aug 2024 22:34:17 +0300 Subject: transform --- res/shaders/triangle.vs | 4 +++- src/main.odin | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/res/shaders/triangle.vs b/res/shaders/triangle.vs index 57cbc74..a6b5b4b 100644 --- a/res/shaders/triangle.vs +++ b/res/shaders/triangle.vs @@ -6,9 +6,11 @@ layout (location = 2) in vec2 a_tex_coord; out vec3 our_color; out vec2 TexCoord; +uniform mat4 transform; + void main() { - gl_Position = vec4(a_pos, 1.0); + gl_Position = transform * vec4(a_pos, 1.0); our_color = a_color; TexCoord = vec2(a_tex_coord.x, a_tex_coord.y); } diff --git a/src/main.odin b/src/main.odin index 47dd6d5..9f3e5b5 100644 --- a/src/main.odin +++ b/src/main.odin @@ -7,6 +7,7 @@ import "base:intrinsics" import "base:runtime" import "core:c/libc" import "core:fmt" +import "core:math/linalg" import "core:os" import "shader" @@ -192,8 +193,8 @@ main :: proc() { image.image_free(data) shader.use(shdr) - gl.Uniform1i(gl.GetUniformLocation(shdr.id, cstring("texture1")), i32(0)) - gl.Uniform1i(gl.GetUniformLocation(shdr.id, cstring("texture2")), i32(1)) + shader.set_value(shdr, cstring("texture1"), 0) + shader.set_value(shdr, cstring("texture2"), 1) //gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE) @@ -208,7 +209,18 @@ main :: proc() { gl.ActiveTexture(gl.TEXTURE1) gl.BindTexture(gl.TEXTURE_2D, texture2) + trans_vector := linalg.Vector3f32{0.5, -0.5, 0.0} + transform := linalg.matrix4_translate(trans_vector) + transform *= linalg.matrix4_rotate_f32( + f32(glfw.GetTime()), + linalg.Vector3f32{0.0, 0.0, 1.0}, + ) + shader.use(shdr) + + transform_loc := gl.GetUniformLocation(shdr.id, cstring("transform")) + gl.UniformMatrix4fv(transform_loc, 1, gl.FALSE, &transform[0, 0]) + gl.BindVertexArray(vao) gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) -- cgit 1.4.1-2-gfad0