/// utility function for loading a 2D texture from file
/// NOTE: not the version from common.rs, slightly adapted for this tutorial
utility function for loading a 2D texture from file
NOTE: not the version from common.rs, slightly adapted for this tutorial
utility function for loading a 2D texture from file NOTE : not the version from common . rs slightly adapted for this tutorial
pub fn load_texture(path: PathBuf) -> u32 {
    let texture_id = gl::gen_texture();
    let path = path.as_path();
    let img = image::open(&path).expect("Texture failed to load");
    let format = match img {
        ImageLuma8(_) => GL_RED,
        ImageLumaA8(_) => GL_RG,
        ImageRgb8(_) => GL_RGB,
        ImageRgba8(_) => GL_RGBA,
        _ => panic!("unhandled image format"),
    };
    let data = img.as_bytes();
    gl::bind_texture(GL_TEXTURE_2D, texture_id);
    gl::tex_image_2d(
        GL_TEXTURE_2D,
        0,
        format as i32,
        img.width() as i32,
        img.height() as i32,
        0,
        format,
        GL_UNSIGNED_BYTE,
        &data,
    );
    gl::generate_mipmap(GL_TEXTURE_2D);
    gl::tex_parameteri(
        GL_TEXTURE_2D,
        GL_TEXTURE_WRAP_S,
        if format == GL_RGBA { GL_CLAMP_TO_EDGE } else { GL_REPEAT } as i32,
    ); // for this tutorial: use GL_CLAMP_TO_EDGE to prevent semi-transparent borders. Due to interpolation it takes texels from next repeat );
    gl::tex_parameteri(
        GL_TEXTURE_2D,
        GL_TEXTURE_WRAP_T,
        if format == GL_RGBA { GL_CLAMP_TO_EDGE } else { GL_REPEAT } as i32,
    );
    gl::tex_parameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR as i32);
    gl::tex_parameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR as i32);
    texture_id
}
pub fn load_texture ( path : PathBuf ) -> u32 { let texture_id = gl :: gen_texture ( ) ; let path = path . as_path ( ) ; let img = image :: open ( & path ) . expect ( " " ) ; let format = match img { ImageLuma8 ( _ ) => GL_RED , ImageLumaA8 ( _ ) => GL_RG , ImageRgb8 ( _ ) => GL_RGB , ImageRgba8 ( _ ) => GL_RGBA , _ => panic ! ( " " ) , } ; let data = img . as_bytes ( ) ; gl :: bind_texture ( GL_TEXTURE_2D , texture_id ) ; gl :: tex_image_2d ( GL_TEXTURE_2D , 0 , format as i32 , img . width ( ) as i32 , img . height ( ) as i32 , 0 , format , GL_UNSIGNED_BYTE , & data , ) ; gl :: generate_mipmap ( GL_TEXTURE_2D ) ; gl :: tex_parameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , if format == GL_RGBA { GL_CLAMP_TO_EDGE } else { GL_REPEAT } as i32 , ) ; // for this tutorial: use GL_CLAMP_TO_EDGE to prevent semi-transparent borders. Due to interpolation it takes texels from next repeat ); gl :: tex_parameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , if format == GL_RGBA { GL_CLAMP_TO_EDGE } else { GL_REPEAT } as i32 , ) ; gl :: tex_parameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR_MIPMAP_LINEAR as i32 ) ; gl :: tex_parameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR as i32 ) ; texture_id }
utility function for loading a 2D texture from file
NOTE: not the version from common.rs, slightly adapted for this tutorial
utility function for loading a 2D texture from file NOTE : not the version from common . rs slightly adapted for this tutorial
path
PathBuf