Skip to content

Commit

Permalink
Draw the chair with triangles
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Jan 8, 2025
1 parent 19901aa commit 2703127
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 7 additions & 6 deletions example/chair.odin
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ chair_obj_bytes := #load("./public/chair.obj", string)

@private
setup_chair :: proc(s: ^State_Chair, program: gl.Program) {

gl.Enable(gl.CULL_FACE) // don't draw back faces
gl.Enable(gl.DEPTH_TEST) // draw only closest faces

data := obj.data_make(context.temp_allocator)
it := chair_obj_bytes
Expand All @@ -39,25 +42,23 @@ setup_chair :: proc(s: ^State_Chair, program: gl.Program) {

o.vao = gl.CreateVertexArray()

lines := obj.object_to_lines(data, object, context.allocator)
lines := obj.object_to_triangles(data, object, context.allocator)

o.positions = lines.pos[:len(lines)]
o.colors = lines.col[:len(lines)]

for &pos in o.positions {
pos *= 100
pos.y -= 300
}

slice.fill(o.colors, GREEN)
slice.fill(o.colors, rand_color())


gl.BindVertexArray(o.vao)

input_locations_boxes(&o.locations, program)

// gl.Enable(gl.CULL_FACE) // don't draw back faces
// gl.Enable(gl.DEPTH_TEST) // draw only closest faces

attribute(o.a_position, gl.CreateBuffer(), o.positions)
attribute(o.a_color , gl.CreateBuffer(), o.colors)
}
Expand Down Expand Up @@ -98,7 +99,7 @@ frame_chair :: proc(s: ^State_Chair, delta: f32) {

uniform(o.u_matrix, mat)

gl.DrawArrays(gl.LINES, 0, len(o.positions))
gl.DrawArrays(gl.TRIANGLES, 0, len(o.positions))
}

}
4 changes: 0 additions & 4 deletions example/suzanne.odin
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ setup_suzanne :: proc(s: ^State_Suzanne, program: gl.Program) {
pos *= 100
}

// rand_colors(s.colors)
slice.fill(s.colors, GREEN)

/* Init rotation */
Expand All @@ -48,9 +47,6 @@ setup_suzanne :: proc(s: ^State_Suzanne, program: gl.Program) {

input_locations_boxes(s, program)

// gl.Enable(gl.CULL_FACE) // don't draw back faces
// gl.Enable(gl.DEPTH_TEST) // draw only closest faces

attribute(s.a_position, gl.CreateBuffer(), s.positions)
attribute(s.a_color , gl.CreateBuffer(), s.colors)
}
Expand Down

0 comments on commit 2703127

Please sign in to comment.