Display a ground chunk with a given biome

This commit is contained in:
2022-10-16 23:30:23 +02:00
parent d75a564805
commit 5236c99383
2 changed files with 63 additions and 34 deletions
+8 -3
View File
@@ -18,10 +18,15 @@ fn main() {
// building the vertex and index buffers // building the vertex and index buffers
let vertex_buffer = support::load_ground(&display); let vertex_buffer = support::load_ground(&display);
let image = image::load(Cursor::new(&include_bytes!("../opengl.png")), let image = image::load(
image::ImageFormat::Png).unwrap().to_rgba8(); Cursor::new(&include_bytes!("../grassGreen.jpg")),
image::ImageFormat::Jpeg,
)
.unwrap()
.to_rgba8();
let image_dimensions = image.dimensions(); 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(); let texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
// the program // the program
+55 -31
View File
@@ -3,6 +3,7 @@ use glium::glutin::event::{Event, StartCause};
use glium::glutin::event_loop::{ControlFlow, EventLoop}; use glium::glutin::event_loop::{ControlFlow, EventLoop};
use glium::vertex::VertexBufferAny; use glium::vertex::VertexBufferAny;
use glium::{self, Display}; use glium::{self, Display};
use std::fs;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
pub mod camera; pub mod camera;
@@ -65,43 +66,66 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
implement_vertex!(Vertex, position, normal, tex_coords); implement_vertex!(Vertex, position, normal, tex_coords);
let mut vertex_data = Vec::new(); let mut vertex_data: Vec<Vertex> = Vec::new();
vertex_data.push(Vertex { let contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height").expect("Unable to load ground file!");
position: [0.0, 0.0, 0.0],
normal: [0.0, 0.0, 1.0],
tex_coords: [0.0, 0.0],
});
vertex_data.push(Vertex { let lines: Vec<&str> = contents.split('\n').collect();
position: [1.0, 0.0, 0.0],
normal: [0.0, 0.0, 1.0],
tex_coords: [1.0, 0.0],
});
vertex_data.push(Vertex { for lines_index in 0..lines.len() - 1 {
position: [0.0, 0.0, 1.0], let line = lines[lines_index];
normal: [0.0, 0.0, 1.0], let next_line = lines[lines_index + 1];
tex_coords: [0.0, 1.0], 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();
vertex_data.push(Vertex { // TODO: normals if necessary.
position: [1.0, 0.0, 0.0],
normal: [0.0, 0.0, 1.0],
tex_coords: [1.0, 0.0],
});
vertex_data.push(Vertex { // First triangle.
position: [0.0, 0.0, 1.0],
normal: [0.0, 0.0, 1.0],
tex_coords: [0.0, 1.0],
});
vertex_data.push(Vertex { vertex_data.push(Vertex {
position: [1.0, 0.0, 1.0], position: [lines_index as f32, column, columns_index as f32],
normal: [0.0, 0.0, 1.0], normal: [0.0, 0.0, 1.0],
tex_coords: [1.0, 1.0], tex_coords: [0.0, 0.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],
});
// Second triangle.
vertex_data.push(Vertex {
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) glium::vertex::VertexBuffer::new(display, &vertex_data)
.unwrap() .unwrap()