mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
supporting up to 10 textures
This commit is contained in:
parent
fdd770088d
commit
9a624397e0
@ -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)
|
- DejaVuSans.ttf (https://dejavu-fonts.github.io/License.html)
|
||||||
- Puget Sound Regional Council
|
- Puget Sound Regional Council
|
||||||
(https://www.psrc.org/activity-based-travel-model-soundcast)
|
(https://www.psrc.org/activity-based-travel-model-soundcast)
|
||||||
- http://www.textures4photoshop.com for water textures
|
- http://www.textures4photoshop.com for textures
|
||||||
|
@ -5,7 +5,16 @@ uniform vec3 transform;
|
|||||||
// (window width, window height, hatching == 1.0)
|
// (window width, window height, hatching == 1.0)
|
||||||
uniform vec3 window;
|
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 vec4 pass_color;
|
||||||
in vec3 pass_tex_coords;
|
in vec3 pass_tex_coords;
|
||||||
@ -14,8 +23,26 @@ out vec4 f_color;
|
|||||||
void main() {
|
void main() {
|
||||||
if (pass_tex_coords[0] == 0.0) {
|
if (pass_tex_coords[0] == 0.0) {
|
||||||
f_color = pass_color;
|
f_color = pass_color;
|
||||||
} else {
|
} else if (pass_tex_coords[0] == 1.0) {
|
||||||
f_color = texture(tex, vec2(pass_tex_coords[1], pass_tex_coords[2]));
|
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) {
|
if (window[2] == 1.0) {
|
||||||
|
@ -39,7 +39,7 @@ pub struct Canvas {
|
|||||||
pub(crate) lctrl_held: bool,
|
pub(crate) lctrl_held: bool,
|
||||||
|
|
||||||
// TODO Definitely a weird place to stash this!
|
// TODO Definitely a weird place to stash this!
|
||||||
pub(crate) textures: HashMap<String, Texture2d>,
|
pub(crate) textures: Vec<(String, Texture2d)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Canvas {
|
impl Canvas {
|
||||||
@ -70,7 +70,7 @@ impl Canvas {
|
|||||||
hide_modal_menus: false,
|
hide_modal_menus: false,
|
||||||
lctrl_held: false,
|
lctrl_held: false,
|
||||||
|
|
||||||
textures: HashMap::new(),
|
textures: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
fn visit_values<'a, F: FnMut(&str, UniformValue<'a>)>(&'a self, mut output: F) {
|
||||||
output("transform", UniformValue::Vec3(self.transform));
|
output("transform", UniformValue::Vec3(self.transform));
|
||||||
output("window", UniformValue::Vec3(self.window));
|
output("window", UniformValue::Vec3(self.window));
|
||||||
output(
|
for (idx, (_, tex)) in self.canvas.textures.iter().enumerate() {
|
||||||
"tex",
|
output(&format!("tex{}", idx), UniformValue::Texture2d(tex, None));
|
||||||
UniformValue::Texture2d(&self.canvas.textures["assets/water_texture.png"], None),
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,8 @@ impl<'a> Prerender<'a> {
|
|||||||
tex_coords: [
|
tex_coords: [
|
||||||
if color == Color::rgb(170, 211, 223) {
|
if color == Color::rgb(170, 211, 223) {
|
||||||
1.0
|
1.0
|
||||||
|
} else if color == Color::rgb(200, 250, 204) {
|
||||||
|
2.0
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
},
|
},
|
||||||
@ -163,19 +165,6 @@ impl<'a> EventCtx<'a> {
|
|||||||
self.input.window_lost_cursor()
|
self.input.window_lost_cursor()
|
||||||
|| (!self.canvas.is_dragging() && self.input.get_moved_mouse().is_some())
|
|| (!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> {
|
pub struct LoadingScreen<'a> {
|
||||||
@ -202,19 +191,13 @@ impl<'a> LoadingScreen<'a> {
|
|||||||
GlyphBrush::new(prerender.display, vec![Font::from_bytes(dejavu).unwrap()]);
|
GlyphBrush::new(prerender.display, vec![Font::from_bytes(dejavu).unwrap()]);
|
||||||
let mapspace_glyphs =
|
let mapspace_glyphs =
|
||||||
GlyphBrush::new(prerender.display, vec![Font::from_bytes(dejavu).unwrap()]);
|
GlyphBrush::new(prerender.display, vec![Font::from_bytes(dejavu).unwrap()]);
|
||||||
let mut canvas = Canvas::new(
|
let canvas = Canvas::new(
|
||||||
initial_width,
|
initial_width,
|
||||||
initial_height,
|
initial_height,
|
||||||
screenspace_glyphs,
|
screenspace_glyphs,
|
||||||
mapspace_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
|
// TODO Dupe code
|
||||||
let vmetrics = canvas.screenspace_glyphs.borrow().fonts()[0]
|
let vmetrics = canvas.screenspace_glyphs.borrow().fonts()[0]
|
||||||
.v_metrics(Scale::uniform(FONT_SIZE as f32));
|
.v_metrics(Scale::uniform(FONT_SIZE as f32));
|
||||||
|
@ -156,6 +156,7 @@ pub fn run<G: GUI, F: FnOnce(&mut EventCtx) -> G>(
|
|||||||
window_title: &str,
|
window_title: &str,
|
||||||
initial_width: f64,
|
initial_width: f64,
|
||||||
initial_height: f64,
|
initial_height: f64,
|
||||||
|
textures: Vec<&str>,
|
||||||
make_gui: F,
|
make_gui: F,
|
||||||
) {
|
) {
|
||||||
let events_loop = glutin::EventsLoop::new();
|
let events_loop = glutin::EventsLoop::new();
|
||||||
@ -252,6 +253,21 @@ pub fn run<G: GUI, F: FnOnce(&mut EventCtx) -> G>(
|
|||||||
total_bytes_uploaded: Cell::new(0),
|
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 {
|
let gui = make_gui(&mut EventCtx {
|
||||||
input: &mut UserInput::new(Event::NoOp, ContextMenu::new(), &mut canvas),
|
input: &mut UserInput::new(Event::NoOp, ContextMenu::new(), &mut canvas),
|
||||||
canvas: &mut canvas,
|
canvas: &mut canvas,
|
||||||
|
@ -427,7 +427,7 @@ impl GUI for UI {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = 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;
|
ctx.canvas.cam_zoom = 4.0;
|
||||||
UI::new(&args[1], ctx)
|
UI::new(&args[1], ctx)
|
||||||
});
|
});
|
||||||
|
BIN
game/assets/grass_texture.png
Normal file
BIN
game/assets/grass_texture.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
@ -16,8 +16,6 @@ pub struct Game {
|
|||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
pub fn new(flags: Flags, ctx: &mut EventCtx) -> Game {
|
pub fn new(flags: Flags, ctx: &mut EventCtx) -> Game {
|
||||||
ctx.upload_texture("assets/water_texture.png");
|
|
||||||
|
|
||||||
let splash = !flags.no_splash
|
let splash = !flags.no_splash
|
||||||
&& !format!("{}", flags.sim_flags.load.display()).contains("data/save");
|
&& !format!("{}", flags.sim_flags.load.display()).contains("data/save");
|
||||||
let ui = UI::new(flags, ctx, splash);
|
let ui = UI::new(flags, ctx, splash);
|
||||||
|
@ -14,7 +14,11 @@ mod ui;
|
|||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
ezgui::run("A/B Street", 1800.0, 800.0, |ctx| {
|
ezgui::run(
|
||||||
game::Game::new(ui::Flags::from_args(), ctx)
|
"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),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ impl GUI for UI {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = 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))
|
UI::new(args.get(1))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user