Display a ground chunk with a given biome
This commit is contained in:
+8
-3
@@ -18,10 +18,15 @@ fn main() {
|
||||
// building the vertex and index buffers
|
||||
let vertex_buffer = support::load_ground(&display);
|
||||
|
||||
let image = image::load(Cursor::new(&include_bytes!("../opengl.png")),
|
||||
image::ImageFormat::Png).unwrap().to_rgba8();
|
||||
let image = image::load(
|
||||
Cursor::new(&include_bytes!("../grassGreen.jpg")),
|
||||
image::ImageFormat::Jpeg,
|
||||
)
|
||||
.unwrap()
|
||||
.to_rgba8();
|
||||
let image_dimensions = image.dimensions();
|
||||
let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
|
||||
let image =
|
||||
glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
|
||||
let texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
|
||||
|
||||
// the program
|
||||
|
||||
+40
-16
@@ -3,6 +3,7 @@ use glium::glutin::event::{Event, StartCause};
|
||||
use glium::glutin::event_loop::{ControlFlow, EventLoop};
|
||||
use glium::vertex::VertexBufferAny;
|
||||
use glium::{self, Display};
|
||||
use std::fs;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub mod camera;
|
||||
@@ -65,44 +66,67 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
||||
|
||||
implement_vertex!(Vertex, position, normal, tex_coords);
|
||||
|
||||
let mut vertex_data = Vec::new();
|
||||
let mut vertex_data: Vec<Vertex> = Vec::new();
|
||||
|
||||
let contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height").expect("Unable to load ground file!");
|
||||
|
||||
let lines: Vec<&str> = contents.split('\n').collect();
|
||||
|
||||
for lines_index in 0..lines.len() - 1 {
|
||||
let line = lines[lines_index];
|
||||
let next_line = lines[lines_index + 1];
|
||||
let columns: Vec<&str> = line.split(' ').collect();
|
||||
let next_columns: Vec<&str> = next_line.split(' ').collect();
|
||||
for columns_index in 0..columns.len() - 1 {
|
||||
let column = columns[columns_index].parse::<f32>().unwrap();
|
||||
let column_right = columns[columns_index + 1].parse::<f32>().unwrap();
|
||||
let column_below = next_columns[columns_index].parse::<f32>().unwrap();
|
||||
let column_below_right = next_columns[columns_index + 1].parse::<f32>().unwrap();
|
||||
|
||||
// TODO: normals if necessary.
|
||||
|
||||
// First triangle.
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 0.0],
|
||||
position: [lines_index as f32, column, columns_index as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
position: [lines_index as f32, column_right, (columns_index + 1) as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
position: [(lines_index + 1) as f32, column_below, columns_index as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
// Second triangle.
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 1.0],
|
||||
position: [(lines_index + 1) as f32, column_below_right, (columns_index + 1) as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 1.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [lines_index as f32, column_right, (columns_index + 1) as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [(lines_index + 1) as f32, column_below, columns_index as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
glium::vertex::VertexBuffer::new(display, &vertex_data)
|
||||
.unwrap()
|
||||
.into()
|
||||
|
||||
Reference in New Issue
Block a user