我用的是胶质,我试着用一个结构来简化纹理的使用。问题是,我用来初始化结构的函数接受&'static str作为参数,但是include_bytes!()宏不接受它,编译器说参数必须是字符串文本。以下是功能失调的代码:
fn load(path : String, format : ImageFormat, display : glium::Display) -> Image{
let image = image::load(Cursor::new(&include_bytes!(path)[..]),
format).unwrap().to_rgba8();
let image_dimensions = image.dimensions();
let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
let _opengl_texture = glium::texture::CompressedSrgbTexture2d::new(&display, image).unwrap();
return Image{opengl_texture : _opengl_texture}
}我试着使用String并以多种方式转换它,但它仍然没有工作。
发布于 2022-10-25 18:07:28
include_bytes!宏用于在编译时从文件中加载数据并将其嵌入到可执行文件中。因此,必须通过字符串文本在编译时知道路径。您的path变量只有在运行时才知道。
也许你想要的是std::fs::read?
https://stackoverflow.com/questions/74198327
复制相似问题