From ab03d50a2ff7eb2e80cce86332d819420b4cb952 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 26 Jan 2020 00:31:26 +0000 Subject: [PATCH] Extract point_to_model --- src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 479cc53..5b7690c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -516,6 +516,15 @@ unsafe fn vertex_attrib_pointer (id: Option , num_coords: i32, slice: &[u8] } } +unsafe fn point_to_model ( + attrs: &HashMap >, + model: &IqmModel +) { + vertex_attrib_pointer (attrs ["pos"], 3, model.get_vertex_slice (0)); + vertex_attrib_pointer (attrs ["uv"], 2, model.get_vertex_slice (1)); + vertex_attrib_pointer (attrs ["normal"], 3, model.get_vertex_slice (2)); +} + fn main () { let sdl_context = sdl2::init ().unwrap (); let video_subsystem = sdl_context.video ().unwrap (); @@ -626,8 +635,6 @@ fn main () { let mut spin_speed: i32 = 0; const SPIN_RAMP_TIME: i32 = 30; - //println! ("Entering main loop"); - let mut event_pump = sdl_context.event_pump ().unwrap (); 'running: loop { let frame_time = Instant::now (); @@ -735,9 +742,7 @@ fn main () { gl::Uniform3fv (unis ["albedo"], 1, &orange as *const Vec3 as *const f32); - vertex_attrib_pointer (attrs ["pos"], 3, model.get_vertex_slice (0)); - vertex_attrib_pointer (attrs ["uv"], 2, model.get_vertex_slice (1)); - vertex_attrib_pointer (attrs ["normal"], 3, model.get_vertex_slice (2)); + point_to_model (&attrs, &model); gl::DrawElements (gl::TRIANGLES, (model.meshes [0].num_triangles * 3) as i32, gl::UNSIGNED_INT, &model.get_index_slice (0) [0] as *const u8 as *const c_void); @@ -758,9 +763,7 @@ fn main () { gl::Uniform3fv (unis ["min_albedo"], 1, &black as *const Vec3 as *const f32); gl::Uniform1i (unis ["texture"], 0); - vertex_attrib_pointer (attrs ["pos"], 3, sky_model.get_vertex_slice (0)); - vertex_attrib_pointer (attrs ["uv"], 2, sky_model.get_vertex_slice (1)); - vertex_attrib_pointer (attrs ["normal"], 3, sky_model.get_vertex_slice (2)); + point_to_model (&attrs, &sky_model); gl::DrawElements (gl::TRIANGLES, (sky_model.meshes [0].num_triangles * 3) as i32, gl::UNSIGNED_INT, &sky_model.get_index_slice (0) [0] as *const u8 as *const c_void); }