diff --git a/src/main.rs b/src/main.rs index 6653e52..5773299 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,7 +181,10 @@ fn main() { let mut camera = support::camera::CameraState::new(); - let vertex_buffer = support::load_wavefront(&display, &load_bytes!("../Extensions/LemnosLife/Map/Common/Structures/24.obj")); + let vertex_buffer = support::load_wavefront( + &display, + load_bytes!("../Extensions/LemnosLife/Map/Common/Structures/24.obj"), + ); let structures_program = program!(&display, 140 => { @@ -193,8 +196,11 @@ fn main() { in vec3 w_position; in vec3 position; + in vec2 texture; + out vec2 v_texture; void main() { + v_texture = texture; gl_Position = persp_matrix * view_matrix * vec4(position + w_position, 1.0); } ", @@ -202,14 +208,18 @@ fn main() { fragment: " #version 140 + uniform sampler2D tex; + + in vec2 v_texture; out vec4 f_color; void main() { - f_color = vec4(1.0, 1.0, 1.0, 1.0); + f_color = texture(tex, v_texture); } ", }, - ).unwrap(); + ) + .unwrap(); let per_instance = vec![ PerInstance { @@ -252,6 +262,7 @@ fn main() { let structures_uniforms = uniform! { persp_matrix: camera.get_perspective(), view_matrix: camera.get_view(), + tex: &textures[0], }; // draw parameters diff --git a/src/support/mod.rs b/src/support/mod.rs index 3d6b670..c3cf91f 100644 --- a/src/support/mod.rs +++ b/src/support/mod.rs @@ -119,7 +119,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { fs::read_to_string(&format!( "Extensions/LemnosLife/Map/Altis/{folder}/{file_name}.{extension}" )) - .expect(&format!("Unable to load {} file!", extension)) + .unwrap_or_else(|_| panic!("Unable to load {} file!", extension)) }); let height_lines: Vec<&str> = height_contents.split('\n').rev().collect(); @@ -144,7 +144,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { for columns_index in 0..height_columns.len() { let [column, column_below]: [f32; 2] = [&height_columns, &height_next_columns] - .map(|height_columns| get_altitude(&height_columns, columns_index)); + .map(|height_columns| get_altitude(height_columns, columns_index)); let biome_index = if lines_index % 2 == 0 { columns_index @@ -215,17 +215,13 @@ pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny { for polygon in object.groups.iter().flat_map(|g| g.polys.iter()) { match polygon { obj::SimplePolygon(indices) => { - for i in 0..=2 { - let v = indices[i]; + for v in indices.iter().take(3) { let position = data.position[v.0]; let texture = v.1.map(|index| data.texture[index]); let texture = texture.unwrap_or([0.0, 0.0]); - vertex_data.push(Vertex { - position, - texture, - }) + vertex_data.push(Vertex { position, texture }) } for i in [0, 2, 3] { let v = indices[i]; @@ -234,16 +230,13 @@ pub fn load_wavefront(display: &Display, data: &[u8]) -> VertexBufferAny { let texture = texture.unwrap_or([0.0, 0.0]); - vertex_data.push(Vertex { - position, - texture, - }) + vertex_data.push(Vertex { position, texture }) } - }, + } } } } glium::vertex::VertexBuffer::new(display, &vertex_data) .unwrap() .into() -} \ No newline at end of file +}