You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ran into a bug today when trying to set up two meshes with different textures. Essentially, which ever texture I use last, becomes the texture used by the other mesh:
use std::path::PathBuf;
use nannou::image::GenericImageView;
use nannou::prelude::*;
use palette;
const UPDATE_FPS_COUNT: u64 = 100;
pub fn run() {
nannou::app(model)
.update(update)
.simple_window(view)
.run();
}
struct ImageTexture {
texture: wgpu::Texture,
image: nannou::image::DynamicImage,
}
impl ImageTexture {
pub fn new(app: &App, img_path: PathBuf) -> Self {
let image = nannou::image::open(img_path).unwrap();
let texture = wgpu::Texture::from_image(app, &image);
Self {
texture,
image,
}
}
}
struct Model {
bg_color: Hsl,
island_image_texture: ImageTexture,
tree_image_texture: ImageTexture,
}
fn model(app: &App) -> Model {
let bg_color = Hsl::new(0.0, 0.0, 0.0);
let assets = app.assets_path().unwrap();
let island_img_path = assets.join("images").join("island.png");
let island_image_texture = ImageTexture::new(app, island_img_path);
let tree_img_path = assets.join("images").join("tree.png");
let tree_image_texture = ImageTexture::new(app, tree_img_path);
Model {
bg_color,
island_image_texture,
tree_image_texture,
}
}
fn update(app: &App, model: &mut Model, update: Update) {
let elapsed_frames = app.elapsed_frames();
if elapsed_frames % UPDATE_FPS_COUNT == 0 {
let fps = app.fps();
log::info!("{} fps at {}", fps, elapsed_frames);
}
}
fn view(app: &App, model: &Model, frame: Frame) {
let draw = app.draw();
draw.background().color(palette::named::BLACK);
{
let square = geom::Rect::from_w_h(100.0, 100.0);
let points = square
.triangles_iter()
.flat_map(geom::Tri::vertices)
.map(|point| {
let tex_coords = [
point.x / square.w() + 0.5,
(point.y / square.h() * -1.0) + 0.5,
];
(point, tex_coords)
});
draw.mesh()
.points_textured(&model.island_image_texture.texture, points)
.y_radians(app.time * 0.33);
}
{
let square = geom::Rect::from_w_h(100.0, 100.0);
let points = square
.triangles_iter()
.flat_map(geom::Tri::vertices)
.map(|point| {
let tex_coords = [
point.x / square.w() + 0.5,
(point.y / square.h() * -1.0) + 0.5,
];
(point, tex_coords)
});
draw.mesh()
.points_textured(&model.tree_image_texture.texture, points);
}
draw.to_frame(app, &frame).unwrap();
}
In this code, both meshes display the 'tree_image' whereas if I swap the order, both show the 'island' image.
The text was updated successfully, but these errors were encountered:
I think perhaps this has been fixed on master by #594 which overhauled the way the draw::Renderer creates commands for the render pass which I believe might have addressed this issue.
Sure enough, if I run your snippet above on master (with some small modifications to get it compiling/running locally with local images) it seems to be working with the two textures displaying one on top of the other:
In case you're interested, you can see what other changes are yet to be published to crates.io under the "Unreleased" section of the changelog here.
Perhaps we should publish 0.15 soon as there are quite a few changes pending there now!
Oh excellent. Switching to master fixed it for me too.
Looking forward to the 0.15 bump -- looks like a lot of good stuff around textures. I'll leave this ticket open until that gets bumped in case others run into the same issue.
Ran into a bug today when trying to set up two meshes with different textures. Essentially, which ever texture I use last, becomes the texture used by the other mesh:
In this code, both meshes display the 'tree_image' whereas if I swap the order, both show the 'island' image.
The text was updated successfully, but these errors were encountered: