Extract point_to_model

main
_ 2020-01-26 00:31:26 +00:00
parent 71400eb4ff
commit ab03d50a2f
1 changed files with 11 additions and 8 deletions

View File

@ -516,6 +516,15 @@ unsafe fn vertex_attrib_pointer (id: Option <u32>, num_coords: i32, slice: &[u8]
}
}
unsafe fn point_to_model (
attrs: &HashMap <String, Option <u32>>,
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);
}