diff --git a/docs/INSTRUCTIONS.md b/docs/INSTRUCTIONS.md index f2f5da3ff6..a440255385 100644 --- a/docs/INSTRUCTIONS.md +++ b/docs/INSTRUCTIONS.md @@ -66,4 +66,4 @@ A/B Street binary releases contain pre-built maps that combine data from: - DejaVuSans.ttf (https://dejavu-fonts.github.io/License.html) - Puget Sound Regional Council (https://www.psrc.org/activity-based-travel-model-soundcast) -- http://www.textures4photoshop.com for water textures +- http://www.textures4photoshop.com for textures diff --git a/ezgui/src/assets/fragment_140.glsl b/ezgui/src/assets/fragment_140.glsl index ab91eeb675..e20df63fa4 100644 --- a/ezgui/src/assets/fragment_140.glsl +++ b/ezgui/src/assets/fragment_140.glsl @@ -5,7 +5,16 @@ uniform vec3 transform; // (window width, window height, hatching == 1.0) uniform vec3 window; -uniform sampler2D tex; +uniform sampler2D tex0; +uniform sampler2D tex1; +uniform sampler2D tex2; +uniform sampler2D tex3; +uniform sampler2D tex4; +uniform sampler2D tex5; +uniform sampler2D tex6; +uniform sampler2D tex7; +uniform sampler2D tex8; +uniform sampler2D tex9; in vec4 pass_color; in vec3 pass_tex_coords; @@ -14,8 +23,26 @@ out vec4 f_color; void main() { if (pass_tex_coords[0] == 0.0) { f_color = pass_color; - } else { - f_color = texture(tex, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 1.0) { + f_color = texture(tex0, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 2.0) { + f_color = texture(tex1, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 3.0) { + f_color = texture(tex2, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 4.0) { + f_color = texture(tex3, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 5.0) { + f_color = texture(tex4, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 6.0) { + f_color = texture(tex5, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 7.0) { + f_color = texture(tex6, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 8.0) { + f_color = texture(tex7, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 9.0) { + f_color = texture(tex8, vec2(pass_tex_coords[1], pass_tex_coords[2])); + } else if (pass_tex_coords[0] == 10.0) { + f_color = texture(tex9, vec2(pass_tex_coords[1], pass_tex_coords[2])); } if (window[2] == 1.0) { diff --git a/ezgui/src/canvas.rs b/ezgui/src/canvas.rs index bd4b8b50f8..a65cebd48c 100644 --- a/ezgui/src/canvas.rs +++ b/ezgui/src/canvas.rs @@ -39,7 +39,7 @@ pub struct Canvas { pub(crate) lctrl_held: bool, // TODO Definitely a weird place to stash this! - pub(crate) textures: HashMap, + pub(crate) textures: Vec<(String, Texture2d)>, } impl Canvas { @@ -70,7 +70,7 @@ impl Canvas { hide_modal_menus: false, lctrl_held: false, - textures: HashMap::new(), + textures: Vec::new(), } } diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index 7eaed2f13e..c6a4111360 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -45,10 +45,9 @@ impl<'b> glium::uniforms::Uniforms for Uniforms<'b> { fn visit_values<'a, F: FnMut(&str, UniformValue<'a>)>(&'a self, mut output: F) { output("transform", UniformValue::Vec3(self.transform)); output("window", UniformValue::Vec3(self.window)); - output( - "tex", - UniformValue::Texture2d(&self.canvas.textures["assets/water_texture.png"], None), - ); + for (idx, (_, tex)) in self.canvas.textures.iter().enumerate() { + output(&format!("tex{}", idx), UniformValue::Texture2d(tex, None)); + } } } diff --git a/ezgui/src/event_ctx.rs b/ezgui/src/event_ctx.rs index fd6a3bc8c7..667e4a2a10 100644 --- a/ezgui/src/event_ctx.rs +++ b/ezgui/src/event_ctx.rs @@ -76,6 +76,8 @@ impl<'a> Prerender<'a> { tex_coords: [ if color == Color::rgb(170, 211, 223) { 1.0 + } else if color == Color::rgb(200, 250, 204) { + 2.0 } else { 0.0 }, @@ -163,19 +165,6 @@ impl<'a> EventCtx<'a> { self.input.window_lost_cursor() || (!self.canvas.is_dragging() && self.input.get_moved_mouse().is_some()) } - - // TODO Belongs on Prerender? - pub fn upload_texture(&mut self, filename: &str) { - assert!(!self.canvas.textures.contains_key(filename)); - let img = image::open(filename).unwrap().to_rgba(); - let dims = img.dimensions(); - let tex = glium::texture::Texture2d::new( - self.prerender.display, - glium::texture::RawImage2d::from_raw_rgba_reversed(&img.into_raw(), dims), - ) - .unwrap(); - self.canvas.textures.insert(filename.to_string(), tex); - } } pub struct LoadingScreen<'a> { @@ -202,19 +191,13 @@ impl<'a> LoadingScreen<'a> { GlyphBrush::new(prerender.display, vec![Font::from_bytes(dejavu).unwrap()]); let mapspace_glyphs = GlyphBrush::new(prerender.display, vec![Font::from_bytes(dejavu).unwrap()]); - let mut canvas = Canvas::new( + let canvas = Canvas::new( initial_width, initial_height, screenspace_glyphs, mapspace_glyphs, ); - // TODO Hack - canvas.textures.insert( - "assets/water_texture.png".to_string(), - glium::texture::Texture2d::empty(prerender.display, 800, 600).unwrap(), - ); - // TODO Dupe code let vmetrics = canvas.screenspace_glyphs.borrow().fonts()[0] .v_metrics(Scale::uniform(FONT_SIZE as f32)); diff --git a/ezgui/src/runner.rs b/ezgui/src/runner.rs index 551d4d4221..364d70cd66 100644 --- a/ezgui/src/runner.rs +++ b/ezgui/src/runner.rs @@ -156,6 +156,7 @@ pub fn run G>( window_title: &str, initial_width: f64, initial_height: f64, + textures: Vec<&str>, make_gui: F, ) { let events_loop = glutin::EventsLoop::new(); @@ -252,6 +253,21 @@ pub fn run G>( total_bytes_uploaded: Cell::new(0), }; + if textures.len() > 10 { + panic!("Due to lovely hacks, only 10 textures supported"); + } + for filename in textures { + println!("Uploading texture {}...", filename); + let img = image::open(filename).unwrap().to_rgba(); + let dims = img.dimensions(); + let tex = glium::texture::Texture2d::new( + &display, + glium::texture::RawImage2d::from_raw_rgba_reversed(&img.into_raw(), dims), + ) + .unwrap(); + canvas.textures.push((filename.to_string(), tex)); + } + let gui = make_gui(&mut EventCtx { input: &mut UserInput::new(Event::NoOp, ContextMenu::new(), &mut canvas), canvas: &mut canvas, diff --git a/fix_map_geom/src/main.rs b/fix_map_geom/src/main.rs index afffad34af..1af6715eb6 100644 --- a/fix_map_geom/src/main.rs +++ b/fix_map_geom/src/main.rs @@ -427,7 +427,7 @@ impl GUI for UI { fn main() { let args: Vec = env::args().collect(); - ezgui::run("InitialMap debugger", 1800.0, 800.0, |ctx| { + ezgui::run("InitialMap debugger", 1800.0, 800.0, vec![], |ctx| { ctx.canvas.cam_zoom = 4.0; UI::new(&args[1], ctx) }); diff --git a/game/assets/grass_texture.png b/game/assets/grass_texture.png new file mode 100644 index 0000000000..7951377f7f Binary files /dev/null and b/game/assets/grass_texture.png differ diff --git a/game/src/game.rs b/game/src/game.rs index e71d525d0f..fefd4cbefa 100644 --- a/game/src/game.rs +++ b/game/src/game.rs @@ -16,8 +16,6 @@ pub struct Game { impl Game { pub fn new(flags: Flags, ctx: &mut EventCtx) -> Game { - ctx.upload_texture("assets/water_texture.png"); - let splash = !flags.no_splash && !format!("{}", flags.sim_flags.load.display()).contains("data/save"); let ui = UI::new(flags, ctx, splash); diff --git a/game/src/main.rs b/game/src/main.rs index 9f686e9975..e02330499d 100644 --- a/game/src/main.rs +++ b/game/src/main.rs @@ -14,7 +14,11 @@ mod ui; use structopt::StructOpt; fn main() { - ezgui::run("A/B Street", 1800.0, 800.0, |ctx| { - game::Game::new(ui::Flags::from_args(), ctx) - }); + ezgui::run( + "A/B Street", + 1800.0, + 800.0, + vec!["assets/water_texture.png", "assets/grass_texture.png"], + |ctx| game::Game::new(ui::Flags::from_args(), ctx), + ); } diff --git a/synthetic/src/main.rs b/synthetic/src/main.rs index 1ff4f9a26b..081bc4fdec 100644 --- a/synthetic/src/main.rs +++ b/synthetic/src/main.rs @@ -225,7 +225,7 @@ impl GUI for UI { fn main() { let args: Vec = env::args().collect(); - ezgui::run("Synthetic map editor", 1024.0, 768.0, |_| { + ezgui::run("Synthetic map editor", 1024.0, 768.0, vec![], |_| { UI::new(args.get(1)) }); }