pub fn new(window: &Window, tint: Option<Color>, filename: &str) -> Self {
        let file = std::fs::File::open(filename).unwrap();
        let reader = std::io::BufReader::new(file);
        let image = image::load(reader, image::PNG).unwrap().to_rgba();
        let image_dimensions = image.dimensions();
        let image = RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
        let texture = CompressedTexture2d::new(&window.display, image).unwrap();

        let should_tint = if tint.is_some() { 1 } else { 0 };
        let tint = tint.unwrap_or_else(|| Color::new(1.0, 1.0, 1.0));

        // Size the image relative to the window - calculations assume a square window
        // Assuming 16 game units fit in the (1.0, 1.0) to (-1.0, -1.0) viewspace
        // So: 8 game units per OpenGL unit, a window is 2 OpenGL units high and wide
        let pixels_per_game_unit = window.dimension as f32 * 0.0625;
        let scale_x = image_dimensions.0 as f32 / pixels_per_game_unit / 16.;
        let scale_y = image_dimensions.1 as f32 / pixels_per_game_unit / 16.;

        let vertex_buffer = VertexBuffer::new(
            &window.display,
            &[
                ImgVertex {
                    position: [-scale_x, -scale_y],
                    tex_coords: [0.0, 0.0],
                    tint: tint.into(),
                    should_tint,
                },
                ImgVertex {
                    position: [-scale_x, scale_y],
                    tex_coords: [0.0, 1.0],
                    tint: tint.into(),
                    should_tint,
                },
                ImgVertex {
                    position: [scale_x, scale_y],
                    tex_coords: [1.0, 1.0],
                    tint: tint.into(),
                    should_tint,
                },
                ImgVertex {
                    position: [scale_x, -scale_y],
                    tex_coords: [1.0, 0.0],
                    tint: tint.into(),
                    should_tint,
                },
            ],
        )
        .unwrap();
        let index_buffer = IndexBuffer::new(
            &window.display,
            PrimitiveType::TriangleStrip,
            &[1 as u16, 2, 0, 3],
        )
        .unwrap();
        Self {
            vertex_buffer,
            index_buffer,
            texture,
        }
    }
/// Create a new image.  `filename` is relative to the root of the project you are running from.
/// For example, if you created a `media` subdirectory in the root of your project and then put
/// `soldier.png` in it, then your filename would be `media/soldier.png`.
Create a new image.  `filename` is relative to the root of the project you are running from.
Create a new image . ` filename ` is relative to the root of the project you are running from .
pub fn new(window: &Window, tint: Option<Color>, filename: &str) -> Self {
        let file = std::fs::File::open(filename).unwrap();
        let reader = std::io::BufReader::new(file);
        let image = image::load(reader, image::PNG).unwrap().to_rgba();
        let image_dimensions = image.dimensions();
        let image = RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
        let texture = CompressedTexture2d::new(&window.display, image).unwrap();
        let should_tint = if tint.is_some() { 1 } else { 0 };
        let tint = tint.unwrap_or_else(|| Color::new(1.0, 1.0, 1.0));
        // Size the image relative to the window - calculations assume a square window
        // Assuming 16 game units fit in the (1.0, 1.0) to (-1.0, -1.0) viewspace
        // So: 8 game units per OpenGL unit, a window is 2 OpenGL units high and wide
        let pixels_per_game_unit = window.dimension as f32 * 0.0625;
        let scale_x = image_dimensions.0 as f32 / pixels_per_game_unit / 16.;
        let scale_y = image_dimensions.1 as f32 / pixels_per_game_unit / 16.;
        let vertex_buffer = VertexBuffer::new(
            &window.display,
            &[
                ImgVertex {
                    position: [-scale_x, -scale_y],
                    tex_coords: [0.0, 0.0],
                    tint: tint.into(),
                    should_tint,
                },
                ImgVertex {
                    position: [-scale_x, scale_y],
                    tex_coords: [0.0, 1.0],
                    tint: tint.into(),
                    should_tint,
                },
                ImgVertex {
                    position: [scale_x, scale_y],
                    tex_coords: [1.0, 1.0],
                    tint: tint.into(),
                    should_tint,
                },
                ImgVertex {
                    position: [scale_x, -scale_y],
                    tex_coords: [1.0, 0.0],
                    tint: tint.into(),
                    should_tint,
                },
            ],
        )
        .unwrap();
        let index_buffer = IndexBuffer::new(
            &window.display,
            PrimitiveType::TriangleStrip,
            &[1 as u16, 2, 0, 3],
        )
        .unwrap();
        Self {
            vertex_buffer,
            index_buffer,
            texture,
        }
    }
pub fn new ( window : & Window , tint : Option < Color > , filename : & str ) -> Self { let file = std :: fs :: File :: open ( filename ) . unwrap ( ) ; let reader = std :: io :: BufReader :: new ( file ) ; let image = image :: load ( reader , image :: PNG ) . unwrap ( ) . to_rgba ( ) ; let image_dimensions = image . dimensions ( ) ; let image = RawImage2d :: from_raw_rgba_reversed ( & image . into_raw ( ) , image_dimensions ) ; let texture = CompressedTexture2d :: new ( & window . display , image ) . unwrap ( ) ; let should_tint = if tint . is_some ( ) { 1 } else { 0 } ; let tint = tint . unwrap_or_else ( | | Color :: new ( 1.0 , 1.0 , 1.0 ) ) ; // Size the image relative to the window - calculations assume a square window // Assuming 16 game units fit in the (1.0, 1.0) to (-1.0, -1.0) viewspace // So: 8 game units per OpenGL unit, a window is 2 OpenGL units high and wide let pixels_per_game_unit = window . dimension as f32 * 0.0625 ; let scale_x = image_dimensions . 0 as f32 / pixels_per_game_unit / 16. ; let scale_y = image_dimensions . 1 as f32 / pixels_per_game_unit / 16. ; let vertex_buffer = VertexBuffer :: new ( & window . display , & [ ImgVertex { position : [ - scale_x , - scale_y ] , tex_coords : [ 0.0 , 0.0 ] , tint : tint . into ( ) , should_tint , } , ImgVertex { position : [ - scale_x , scale_y ] , tex_coords : [ 0.0 , 1.0 ] , tint : tint . into ( ) , should_tint , } , ImgVertex { position : [ scale_x , scale_y ] , tex_coords : [ 1.0 , 1.0 ] , tint : tint . into ( ) , should_tint , } , ImgVertex { position : [ scale_x , - scale_y ] , tex_coords : [ 1.0 , 0.0 ] , tint : tint . into ( ) , should_tint , } , ] , ) . unwrap ( ) ; let index_buffer = IndexBuffer :: new ( & window . display , PrimitiveType :: TriangleStrip , & [ 1 as u16 , 2 , 0 , 3 ] , ) . unwrap ( ) ; Self { vertex_buffer , index_buffer , texture , } }
Create a new image.
Create a new image .
window
&Window
tint
Option<Color>
filename
&str
window
&Window
tint
Option<Color>
filename
&str