Ready to use an uniform array of textures for the biomes
This commit is contained in:
+29
-11
@@ -1,13 +1,20 @@
|
||||
#[macro_use]
|
||||
extern crate glium;
|
||||
|
||||
#[macro_use]
|
||||
extern crate load_file;
|
||||
|
||||
use std::io::Cursor;
|
||||
use glium::texture::SrgbTexture2d;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use glium::{glutin, Surface};
|
||||
|
||||
mod support;
|
||||
|
||||
const BIOMES_NUMBER: usize = 19;
|
||||
const BIOMES: [&str; BIOMES_NUMBER] = ["dirt", "grassDry", "grassGreen", "concrete", "soil", "beach", "seabed", "thorn", "wildField", "rock", "grassWild", "stony", "forestPine", "mud", "stonyThistle", "marsh", "dead", "desert", "weed"];
|
||||
|
||||
fn main() {
|
||||
// building the display, ie. the main object
|
||||
let event_loop = glutin::event_loop::EventLoop::new();
|
||||
@@ -18,16 +25,21 @@ fn main() {
|
||||
// building the vertex and index buffers
|
||||
let vertex_buffer = support::load_ground(&display);
|
||||
|
||||
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 texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
|
||||
let textures: [SrgbTexture2d; BIOMES_NUMBER] = BIOMES.map(|biome| {
|
||||
println!("{}", biome);
|
||||
let image = image::load(
|
||||
Cursor::new(&load_bytes!(
|
||||
&format!("../Extensions/LemnosLife/Assets/Pictures/Map/Ground/{}.jpg", biome)
|
||||
)),
|
||||
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);
|
||||
glium::texture::SrgbTexture2d::new(&display, image).unwrap()
|
||||
});
|
||||
|
||||
// the program
|
||||
let program = program!(&display,
|
||||
@@ -38,15 +50,19 @@ fn main() {
|
||||
uniform mat4 persp_matrix;
|
||||
uniform mat4 view_matrix;
|
||||
|
||||
// can't skip directly to fragment shader an unmodified variable?
|
||||
in vec3 normal;
|
||||
in uint index;
|
||||
in float altitude;
|
||||
in uint biome;
|
||||
|
||||
out vec3 v_normal;
|
||||
out vec2 v_tex_coords;
|
||||
out uint v_biome;
|
||||
|
||||
void main() {
|
||||
v_normal = normal;
|
||||
v_biome = biome;
|
||||
uint index_mod = index % 6u;
|
||||
uint index_div = index / 6u;
|
||||
uint z = index_div / 250u;
|
||||
@@ -79,7 +95,9 @@ fn main() {
|
||||
in vec3 v_normal;
|
||||
in vec2 v_tex_coords;
|
||||
out vec4 f_color;
|
||||
in uint v_biome;
|
||||
|
||||
// TODO: not hardcode
|
||||
uniform sampler2D tex;
|
||||
|
||||
const vec3 LIGHT = vec3(0.0, -1.0, 0.0);
|
||||
@@ -103,7 +121,7 @@ fn main() {
|
||||
let uniforms = uniform! {
|
||||
persp_matrix: camera.get_perspective(),
|
||||
view_matrix: camera.get_view(),
|
||||
tex: &texture,
|
||||
tex: &textures[0] // could inline otherwise
|
||||
};
|
||||
|
||||
// draw parameters
|
||||
|
||||
Reference in New Issue
Block a user