diff --git a/src/main.rs b/src/main.rs index 0bf6ecd..43deb5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,17 +38,38 @@ fn main() { uniform mat4 persp_matrix; uniform mat4 view_matrix; - in vec3 position; in vec3 normal; - in vec2 tex_coords; + in uint index; + in float altitude; out vec3 v_normal; out vec2 v_tex_coords; void main() { v_normal = normal; - v_tex_coords = tex_coords; - gl_Position = persp_matrix * view_matrix * vec4(position * 0.005, 1.0); + uint index_mod = index % 6u; + uint index_div = index / 6u; + uint z = index_div / 250u; + uint x = index_div % 250u; + if(index_mod == 0u) + v_tex_coords = vec2(0, 0); + else if(index_mod == 1u || index_mod == 4u) + { + v_tex_coords = vec2(0, 1); + x++; + } + else if(index_mod == 2u || index_mod == 3u) + { + v_tex_coords = vec2(1, 0); + z++; + } + else //if(index_mod == 5u) + { + v_tex_coords = vec2(1, 1); + x++; + z++; + } + gl_Position = persp_matrix * view_matrix * vec4(vec3(x, altitude, z) * 0.005, 1.0); } ", diff --git a/src/support/mod.rs b/src/support/mod.rs index a0e04b5..cef0c64 100644 --- a/src/support/mod.rs +++ b/src/support/mod.rs @@ -59,12 +59,12 @@ where pub fn load_ground(display: &Display) -> VertexBufferAny { #[derive(Copy, Clone)] struct Vertex { - position: [f32; 3], + altitude: f32, normal: [f32; 3], - tex_coords: [f32; 2], + index: u32, } - implement_vertex!(Vertex, position, normal, tex_coords); + implement_vertex!(Vertex, altitude, normal, index); let mut vertex_data: Vec = Vec::new(); @@ -72,6 +72,8 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { let lines: Vec<&str> = contents.split('\n').collect(); + let mut index: u32 = 0; + for lines_index in 0..lines.len() - 1 { let line = lines[lines_index]; let next_line = lines[lines_index + 1]; @@ -88,42 +90,48 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { // First triangle. vertex_data.push(Vertex { - position: [lines_index as f32, column, columns_index as f32], + altitude: column, normal: [0.0, 0.0, 1.0], - tex_coords: [0.0, 0.0], + index, }); + index += 1; vertex_data.push(Vertex { - position: [lines_index as f32, column_right, (columns_index + 1) as f32], + altitude: column_right, normal: [0.0, 0.0, 1.0], - tex_coords: [0.0, 1.0], + index, }); + index += 1; vertex_data.push(Vertex { - position: [(lines_index + 1) as f32, column_below, columns_index as f32], + altitude: column_below, normal: [0.0, 0.0, 1.0], - tex_coords: [1.0, 0.0], + index, }); + index += 1; // Second triangle. vertex_data.push(Vertex { - position: [(lines_index + 1) as f32, column_below, columns_index as f32], + altitude: column_below, normal: [0.0, 0.0, 1.0], - tex_coords: [1.0, 0.0], + index, }); + index += 1; vertex_data.push(Vertex { - position: [lines_index as f32, column_right, (columns_index + 1) as f32], + altitude: column_right, normal: [0.0, 0.0, 1.0], - tex_coords: [0.0, 1.0], + index, }); + index += 1; vertex_data.push(Vertex { - position: [(lines_index + 1) as f32, column_below_right, (columns_index + 1) as f32], + altitude: column_below_right, normal: [0.0, 0.0, 1.0], - tex_coords: [1.0, 1.0], + index, }); + index += 1; } }