diff options
author | iurii plugatarov <[email protected]> | 2024-08-17 18:18:42 +0200 |
---|---|---|
committer | iurii plugatarov <[email protected]> | 2024-08-17 18:18:42 +0200 |
commit | 7d307c75d3cdf724658b577a9e1c8c8e8d98fc42 (patch) | |
tree | d164cbf6de494bd8ccce280a5ef963e4f6630fc0 | |
parent | 20f1e487c8cbb8a23b2759d1934fffc5b6b38156 (diff) | |
download | funhalla-7d307c75d3cdf724658b577a9e1c8c8e8d98fc42.tar.gz |
cube
Diffstat (limited to '')
-rw-r--r-- | res/shaders/triangle.fs | 1 | ||||
-rw-r--r-- | res/shaders/triangle.vs | 5 | ||||
-rw-r--r-- | src/main.odin | 188 |
3 files changed, 163 insertions, 31 deletions
diff --git a/res/shaders/triangle.fs b/res/shaders/triangle.fs index 70a5f6d..1d73089 100644 --- a/res/shaders/triangle.fs +++ b/res/shaders/triangle.fs @@ -2,7 +2,6 @@ out vec4 FragColor; -in vec3 our_color; in vec2 TexCoord; uniform sampler2D texture1; diff --git a/res/shaders/triangle.vs b/res/shaders/triangle.vs index c607a81..4c7fab8 100644 --- a/res/shaders/triangle.vs +++ b/res/shaders/triangle.vs @@ -1,9 +1,7 @@ #version 330 core layout (location = 0) in vec3 a_pos; -layout (location = 1) in vec3 a_color; -layout (location = 2) in vec2 a_tex_coord; +layout (location = 1) in vec2 a_tex_coord; -out vec3 our_color; out vec2 TexCoord; uniform mat4 model; @@ -13,6 +11,5 @@ uniform mat4 projection; void main() { 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 bf275fe..b343013 100644 --- a/src/main.odin +++ b/src/main.odin @@ -61,46 +61,192 @@ main :: proc() { } vertices: []f32 = { + -0.5, + -0.5, + -0.5, + 0.0, + 0.0, + 0.5, + -0.5, + -0.5, + 1.0, + 0.0, + 0.5, + 0.5, + -0.5, + 1.0, + 1.0, + 0.5, + 0.5, + -0.5, + 1.0, + 1.0, + -0.5, + 0.5, + -0.5, + 0.0, + 1.0, + -0.5, + -0.5, + -0.5, + 0.0, + 0.0, + -0.5, + -0.5, + 0.5, + 0.0, + 0.0, + 0.5, + -0.5, + 0.5, + 1.0, + 0.0, 0.5, 0.5, + 0.5, + 1.0, + 1.0, + 0.5, + 0.5, + 0.5, + 1.0, + 1.0, + -0.5, + 0.5, + 0.5, + 0.0, + 1.0, + -0.5, + -0.5, + 0.5, + 0.0, + 0.0, + -0.5, + 0.5, + 0.5, + 1.0, 0.0, + -0.5, + 0.5, + -0.5, 1.0, + 1.0, + -0.5, + -0.5, + -0.5, 0.0, + 1.0, + -0.5, + -0.5, + -0.5, 0.0, 1.0, - 1.0, // top right + -0.5, + -0.5, 0.5, + 0.0, + 0.0, -0.5, + 0.5, + 0.5, + 1.0, 0.0, + 0.5, + 0.5, + 0.5, + 1.0, 0.0, + 0.5, + 0.5, + -0.5, + 1.0, 1.0, + 0.5, + -0.5, + -0.5, 0.0, 1.0, - 0.0, // bottom right + 0.5, + -0.5, -0.5, + 0.0, + 1.0, + 0.5, -0.5, + 0.5, + 0.0, + 0.0, + 0.5, + 0.5, + 0.5, + 1.0, 0.0, + -0.5, + -0.5, + -0.5, 0.0, + 1.0, + 0.5, + -0.5, + -0.5, + 1.0, + 1.0, + 0.5, + -0.5, + 0.5, + 1.0, 0.0, + 0.5, + -0.5, + 0.5, 1.0, 0.0, - 0.0, // bottom let + -0.5, + -0.5, + 0.5, + 0.0, + 0.0, + -0.5, + -0.5, + -0.5, + 0.0, + 1.0, -0.5, 0.5, + -0.5, 0.0, 1.0, + 0.5, + 0.5, + -0.5, + 1.0, + 1.0, + 0.5, + 0.5, + 0.5, + 1.0, + 0.0, + 0.5, + 0.5, + 0.5, 1.0, 0.0, + -0.5, + 0.5, + 0.5, + 0.0, + 0.0, + -0.5, + 0.5, + -0.5, 0.0, 1.0, } - indices := []i32{0, 1, 3, 1, 2, 3} - vbo, vao, ebo, texture1, texture2: u32 + vbo, vao, texture1, texture2: u32 gl.GenVertexArrays(1, &vao) gl.GenBuffers(1, &vbo) - gl.GenBuffers(1, &ebo) gl.BindVertexArray(vao) gl.BindBuffer(gl.ARRAY_BUFFER, vbo) @@ -111,24 +257,13 @@ main :: proc() { raw_data(vertices), gl.STATIC_DRAW, ) - gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebo) - gl.BufferData( - gl.ELEMENT_ARRAY_BUFFER, - size_of(i32) * len(indices), - raw_data(indices), - gl.STATIC_DRAW, - ) - - gl.VertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 8 * size_of(f32), 0) + gl.VertexAttribPointer(0, 3, gl.FLOAT, gl.FALSE, 5 * size_of(f32), 0) gl.EnableVertexAttribArray(0) - gl.VertexAttribPointer(1, 3, gl.FLOAT, gl.FALSE, 8 * size_of(f32), 3 * size_of(f32)) + gl.VertexAttribPointer(1, 2, gl.FLOAT, gl.FALSE, 5 * size_of(f32), 3 * size_of(f32)) gl.EnableVertexAttribArray(1) - gl.VertexAttribPointer(2, 2, gl.FLOAT, gl.FALSE, 8 * size_of(f32), 6 * size_of(f32)) - gl.EnableVertexAttribArray(2) - gl.GenTextures(1, &texture1) gl.BindTexture(gl.TEXTURE_2D, texture1) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) @@ -198,21 +333,23 @@ main :: proc() { //gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE) + gl.Enable(gl.DEPTH_TEST) + for !glfw.WindowShouldClose(window) { process_input(&window) gl.ClearColor(0.2, 0.3, 0.3, 1.0) - gl.Clear(gl.COLOR_BUFFER_BIT) + gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.ActiveTexture(gl.TEXTURE0) gl.BindTexture(gl.TEXTURE_2D, texture1) gl.ActiveTexture(gl.TEXTURE1) gl.BindTexture(gl.TEXTURE_2D, texture2) - model := linalg.matrix4_rotate( - f32(linalg.to_radians(-55.0)), - linalg.Vector3f32{1.0, 0.0, 0.0}, - ) + rotation: f32 = f32(glfw.GetTime()) + + model := linalg.matrix4_rotate(rotation, linalg.Vector3f32{0.5, 1.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( @@ -235,13 +372,12 @@ main :: proc() { gl.BindVertexArray(vao) - gl.DrawElements(gl.TRIANGLES, 6, gl.UNSIGNED_INT, nil) + gl.DrawArrays(gl.TRIANGLES, 0, 36) glfw.SwapBuffers(window) glfw.PollEvents() } - gl.DeleteBuffers(1, &ebo) gl.DeleteVertexArrays(1, &vao) gl.DeleteBuffers(1, &vbo) } |