Explorar el Código

Include resources with include_bytes! macro

Johannes Hofmann hace 7 años
padre
commit
098ebc582a
Se han modificado 2 ficheros con 9 adiciones y 2 borrados
  1. 5
    1
      src/map_view_gl.rs
  2. 4
    1
      src/tile_atlas.rs

+ 5
- 1
src/map_view_gl.rs Ver fichero

@@ -31,7 +31,11 @@ impl<'a> MapViewGl<'a> {
31 31
         ) -> MapViewGl
32 32
         where F: Fn() + Sync + Send + 'static,
33 33
     {
34
-        let mut program = Program::from_paths(cx, "shader/map.vert", "shader/map.frag").unwrap();
34
+        let mut program = Program::new(
35
+            cx,
36
+            include_bytes!("../shader/map.vert"),
37
+            include_bytes!("../shader/map.frag"),
38
+        ).unwrap();
35 39
         check_gl_errors!(cx);
36 40
 
37 41
         let tile_size = 256;

+ 4
- 1
src/tile_atlas.rs Ver fichero

@@ -29,7 +29,10 @@ impl<'a> TileAtlas<'a> {
29 29
     fn init(&mut self) {
30 30
         // add tile for default slot
31 31
         {
32
-            let img = image::open("img/no_tile.png").unwrap();
32
+            let img = image::load_from_memory_with_format(
33
+                include_bytes!("../img/no_tile.png"),
34
+                image::ImageFormat::PNG,
35
+            ).unwrap();
33 36
             self.texture.sub_image(0, 0, &img);
34 37
         }
35 38