fn load_textures(
    textures: Vec<PathBuf>,
) -> Result<(ImageBuffer<Rgba<u8>, Vec<u8>>, Vec<TextureRect>)> {
    use image::GenericImage;
    use texture_packer::{exporter::ImageExporter, importer::ImageImporter};

    let mut packer = TexturePacker::new_skyline(TEXTURE_PACKER_CONFIG);
    for (i, path) in textures.iter().enumerate() {
        packer.pack_own(
            format!("{}", i),
            ImageImporter::import_from_file(path).expect("Failed to read texture to pack"),
        ).expect("Failed to pack textures");
    }

    let mut texture_buffer: ImageBuffer<Rgba<u8>, Vec<u8>> =
        ImageBuffer::new(MAX_TEXTURE_SIZE, MAX_TEXTURE_SIZE);
    texture_buffer.copy_from(
        &ImageExporter::export(&packer).expect("Failed to export texture from packer"),
        0,
        0,
    ).expect("Failed to copy texture atlas to buffer");
    texture_buffer
        .save("atlas.png")
        .expect("Failed to save texture atlas");
    Ok((
        texture_buffer,
        (0..textures.len())
            .map(|i| {
                let frame = packer
                    .get_frame(&format!("{}", i))
                    .expect("Texture packer frame key doesn't exist")
                    .frame;
                TextureRect {
                    x: frame.x as f32 / MAX_TEXTURE_SIZE as f32,
                    y: frame.y as f32 / MAX_TEXTURE_SIZE as f32,
                    width: frame.w as f32 / MAX_TEXTURE_SIZE as f32,
                    height: frame.h as f32 / MAX_TEXTURE_SIZE as f32,
                }
            })
            .collect(),
    ))
}
/// Load given textures to a unique texture atlas
Load given textures to a unique texture atlas
Load given textures to a unique texture atlas
fn load_textures(
    textures: Vec<PathBuf>,
) -> Result<(ImageBuffer<Rgba<u8>, Vec<u8>>, Vec<TextureRect>)> {
    use image::GenericImage;
    use texture_packer::{exporter::ImageExporter, importer::ImageImporter};
    let mut packer = TexturePacker::new_skyline(TEXTURE_PACKER_CONFIG);
    for (i, path) in textures.iter().enumerate() {
        packer.pack_own(
            format!("{}", i),
            ImageImporter::import_from_file(path).expect("Failed to read texture to pack"),
        ).expect("Failed to pack textures");
    }
    let mut texture_buffer: ImageBuffer<Rgba<u8>, Vec<u8>> =
        ImageBuffer::new(MAX_TEXTURE_SIZE, MAX_TEXTURE_SIZE);
    texture_buffer.copy_from(
        &ImageExporter::export(&packer).expect("Failed to export texture from packer"),
        0,
        0,
    ).expect("Failed to copy texture atlas to buffer");
    texture_buffer
        .save("atlas.png")
        .expect("Failed to save texture atlas");
    Ok((
        texture_buffer,
        (0..textures.len())
            .map(|i| {
                let frame = packer
                    .get_frame(&format!("{}", i))
                    .expect("Texture packer frame key doesn't exist")
                    .frame;
                TextureRect {
                    x: frame.x as f32 / MAX_TEXTURE_SIZE as f32,
                    y: frame.y as f32 / MAX_TEXTURE_SIZE as f32,
                    width: frame.w as f32 / MAX_TEXTURE_SIZE as f32,
                    height: frame.h as f32 / MAX_TEXTURE_SIZE as f32,
                }
            })
            .collect(),
    ))
}
fn load_textures ( textures : Vec < PathBuf > , ) -> Result < ( ImageBuffer < Rgba < u8 > , Vec < u8 > > , Vec < TextureRect > ) > { use image :: GenericImage ; use texture_packer :: { exporter :: ImageExporter , importer :: ImageImporter } ; let mut packer = TexturePacker :: new_skyline ( TEXTURE_PACKER_CONFIG ) ; for ( i , path ) in textures . iter ( ) . enumerate ( ) { packer . pack_own ( format ! ( " " i ) , ImageImporter :: import_from_file ( path ) . expect ( " " ) , ) . expect ( " " ) ; } let mut texture_buffer : ImageBuffer < Rgba < u8 > , Vec < u8 > > = ImageBuffer :: new ( MAX_TEXTURE_SIZE , MAX_TEXTURE_SIZE ) ; texture_buffer . copy_from ( & ImageExporter :: export ( & packer ) . expect ( " " ) , 0 , 0 , ) . expect ( " " ) ; texture_buffer . save ( " " ) . expect ( " " ) ; Ok ( ( texture_buffer , ( 0 .. textures . len ( ) ) . map ( | i | { let frame = packer . get_frame ( & format ! ( " " i ) ) . expect ( " " ) . frame ; TextureRect { x : frame . x as f32 / MAX_TEXTURE_SIZE as f32 , y : frame . y as f32 / MAX_TEXTURE_SIZE as f32 , width : frame . w as f32 / MAX_TEXTURE_SIZE as f32 , height : frame . h as f32 / MAX_TEXTURE_SIZE as f32 , } } ) . collect ( ) , ) ) }
Load given textures to a unique texture atlas
Load given textures to a unique texture atlas
textures
Vec<PathBuf>
textures
Vec<PathBuf>