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 /src | |
parent | 20f1e487c8cbb8a23b2759d1934fffc5b6b38156 (diff) | |
download | funhalla-7d307c75d3cdf724658b577a9e1c8c8e8d98fc42.tar.gz |
cube
Diffstat (limited to 'src')
-rw-r--r-- | src/main.odin | 188 |
1 files changed, 162 insertions, 26 deletions
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) } |