diff options
Diffstat (limited to '')
-rw-r--r-- | res/shaders/triangle.vs | 6 | ||||
-rw-r--r-- | src/main.odin | 27 |
2 files changed, 24 insertions, 9 deletions
diff --git a/res/shaders/triangle.vs b/res/shaders/triangle.vs index a6b5b4b..c607a81 100644 --- a/res/shaders/triangle.vs +++ b/res/shaders/triangle.vs @@ -6,11 +6,13 @@ layout (location = 2) in vec2 a_tex_coord; out vec3 our_color; out vec2 TexCoord; -uniform mat4 transform; +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; void main() { - gl_Position = transform * vec4(a_pos, 1.0); + gl_Position = projection * view * model * 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 9f3e5b5..bf275fe 100644 --- a/src/main.odin +++ b/src/main.odin @@ -209,17 +209,30 @@ 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}, + model := linalg.matrix4_rotate( + f32(linalg.to_radians(-55.0)), + linalg.Vector3f32{1.0, 0.0, 0.0}, ) + aspect: f32 = 800.0 / 600.0 + view := linalg.matrix4_translate(linalg.Vector3f32{0.0, 0.0, -3.0}) + projection := linalg.matrix4_perspective_f32( + f32(linalg.to_radians(45.0)), + aspect, + 0.1, + 100.0, + ) + + model_location := gl.GetUniformLocation(shdr.id, "model") + gl.UniformMatrix4fv(model_location, 1, gl.FALSE, &model[0][0]) + + view_location := gl.GetUniformLocation(shdr.id, "view") + gl.UniformMatrix4fv(view_location, 1, gl.FALSE, &view[0][0]) + + projection_location := gl.GetUniformLocation(shdr.id, "projection") + gl.UniformMatrix4fv(projection_location, 1, gl.FALSE, &projection[0][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) |