Repository: glium/glium (language: rust)

Issue:
Book tuto-02-triangle Shader Source
I went though the Tutorials in the book and had a problem running the rust programm.
"thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CompilationError("ERROR: 0:2: '#' : invalid directive \nERROR: 0:2: '' : compilation terminated \nERROR: 2 compilation errors.  No code generated.\n\n", Vertex)', src\main.rs:49:103"

After digging a bit I found out the Version for the shaders should be annotated with a single '#'. In the source code for [Tuto 2](https://github.com/glium/glium/blob/master/examples/tutorial-02.rs) this is done right. In the book however the versions are annotated with '##'.

Just a minor thing I found. Hope that helps.


Discussion / hints:

Fix patch:
diff --git a/book/tuto-01-getting-started.md b/book/tuto-01-getting-started.md
index 07863b6b5b..d01de87748 100644
--- a/book/tuto-01-getting-started.md
+++ b/book/tuto-01-getting-started.md
@@ -40,7 +40,7 @@ This will open a new window, register it with the given event_loop and create a
 
 ```rust
 fn main() {
-    let event_loop = winit::event_loop::EventLoopBuilder::new().build();
+    let event_loop = winit::event_loop::EventLoopBuilder::new().build().expect("event loop building");
     let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
 }
 ```
@@ -48,16 +48,14 @@ fn main() {
 If you try to run this example with `cargo run` you'll encounter a problem: as soon as the window has been created, our main function exits and the window is closed. To prevent this, we need to wait until we receive a `CloseRequested` event. We do this by calling `event_loop.run`:
 
 ```rust
-event_loop.run(move |ev, _, control_flow| {
-    match ev {
+let _ = event_loop.run(move |event, window_target| {
+    match event {
         winit::event::Event::WindowEvent { event, .. } => match event {
-            winit::event::WindowEvent::CloseRequested => {
-                *control_flow =  winit::event_loop::ControlFlow::Exit;
-            },
-            _ => (),
+	    winit::event::WindowEvent::CloseRequested => window_target.exit(),
+	    _ => (),
         },
         _ => (),
-    }
+    };
 });
 ```
 
@@ -102,18 +100,18 @@ Here is our full program:
 use glium::Surface;
 
 fn main() {
-    let event_loop = winit::event_loop::EventLoopBuilder::new().build();
+    let event_loop = winit::event_loop::EventLoopBuilder::new().build().expect("event loop building");
     let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
 
     let mut frame = display.draw();
     frame.clear_color(0.0, 0.0, 1.0, 1.0);
     frame.finish().unwrap();
 
-    event_loop.run(move |event, _, control_flow| {
+    let _ = event_loop.run(move |event, window_target| {
         match event {
             winit::event::Event::WindowEvent { event, .. } => match event {
-                winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
-                _ => (),
+	        winit::event::WindowEvent::CloseRequested => window_target.exit(),
+	        _ => (),
             },
             _ => (),
         };
diff --git a/book/tuto-02-triangle.md b/book/tuto-02-triangle.md
index 197ece6ae2..2864a57ea8 100644
--- a/book/tuto-02-triangle.md
+++ b/book/tuto-02-triangle.md
@@ -78,7 +78,7 @@ The tricky part is that *we* need to write the vertex and fragment shaders. To d
 
 ```rust
 let vertex_shader_src = r#"
-    ##version 140
+    #version 140
 
     in vec2 position;
 
@@ -98,7 +98,7 @@ The second shader is called the fragment shader (sometimes also named *pixel sha
 
 ```rust
 let fragment_shader_src = r#"
-    ##version 140
+    #version 140
 
     out vec4 color;
 
diff --git a/book/tuto-03-animated-triangle.md b/book/tuto-03-animated-triangle.md
index 383f221057..c54b5494f2 100644
--- a/book/tuto-03-animated-triangle.md
+++ b/book/tuto-03-animated-triangle.md
@@ -5,15 +5,15 @@ Now that we have a triangle, we are going to animate it. Remember that OpenGL is
 So far we have only ever rendered a single frame and then waited for the program to exit. For an animation to show we need to change the way we draw our triangle. Instead of drawing a frame and then waiting in our event_loop for the window to close, we first draw our triangle when requested by the operating system:
 
 ```rust
-event_loop.run(move |event, _, control_flow| {
+let _ = event_loop.run(move |event, window_target| {
     match event {
         winit::event::Event::WindowEvent { event, .. } => match event {
-            winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
+            winit::event::WindowEvent::CloseRequested => window_target.exit(),
+            winit::event::WindowEvent::RedrawRequested => {
+                // Move the draw code here!
+            },
             _ => (),
         },
-        winit::event::Event::RedrawRequested(_) => {
-            // Move the draw code here!
-        },
         _ => (),
     };
 });
@@ -22,18 +22,18 @@ event_loop.run(move |event, _, control_flow| {
 What exactly triggers this event is platform specific, but in order to draw our triangle over and over again we can request a redraw ourselves once we've finished rendering, to do that we'll respond to yet another event:
 
 ```rust
-event_loop.run(move |event, _, control_flow| {
+let _ = event_loop.run(move |event, window_target| {
     match event {
         winit::event::Event::WindowEvent { event, .. } => match event {
-            winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
+            winit::event::WindowEvent::CloseRequested => window_target.exit(),
+            winit::event::WindowEvent::RedrawRequested => {
+                // Move the draw code here!
+            },
             _ => (),
         },
-        winit::event::Event::RedrawEventsCleared => {
+        winit::event::Event::AboutToWait => {
             window.request_redraw();
         },
-        winit::event::Event::RedrawRequested(_) => {
-            // Move the draw code here!
-        },
         _ => (),
     };
 });
@@ -45,21 +45,21 @@ While we are working on our event_loop there is one more event that we should ha
 
 ```rust
 let mut t: f32 = 0.0;
-event_loop.run(move |event, _, control_flow| {
+let _ = event_loop.run(move |event, window_target| {
     match event {
         winit::event::Event::WindowEvent { event, .. } => match event {
-            winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
+            winit::event::WindowEvent::CloseRequested => window_target.exit(),
             winit::event::WindowEvent::Resized(window_size) => {
                 display.resize(window_size.into());
             },
+            winit::event::WindowEvent::RedrawRequested => {
+                // Move the draw code here!
+            },
             _ => (),
         },
-        winit::event::Event::RedrawEventsCleared => {
+        winit::event::Event::AboutToWait => {
             window.request_redraw();
         },
-        winit::event::Event::RedrawRequested(_) => {
-            // Move the draw code here!
-        },
         _ => (),
     };
 });
@@ -73,37 +73,37 @@ Our first approach will be to create a variable named `t` which represents the s
 
 ```rust
 let mut t: f32 = 0.0;
-event_loop.run(move |event, _, control_flow| {
+let _ = event_loop.run(move |event, window_target| {
     match event {
         winit::event::Event::WindowEvent { event, .. } => match event {
-            winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
+            winit::event::WindowEvent::CloseRequested => window_target.exit(),
             winit::event::WindowEvent::Resized(window_size) => {
                 display.resize(window_size.into());
             },
+            winit::event::WindowEvent::RedrawRequested => {
+                // We update `t`
+                t += 0.02;
+                // We use the sine of t as an offset, this way we get a nice smooth animation
+                let x_off = t.sin() * 0.5;
+
+                let shape = vec![
+                    Vertex { position: [-0.5 + x_off, -0.5] },
+                    Vertex { position: [ 0.0 + x_off,  0.5] },
+                    Vertex { position: [ 0.5 + x_off, -0.25] }
+                ];
+                let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
+
+                let mut target = display.draw();
+                target.clear_color(0.0, 0.0, 1.0, 1.0);
+                target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
+                        &Default::default()).unwrap();
+                target.finish().unwrap();
+            },
             _ => (),
         },
-        winit::event::Event::RedrawEventsCleared => {
+        winit::event::Event::AboutToWait => {
             window.request_redraw();
         },
-        winit::event::Event::RedrawRequested(_) => {
-            // We update `t`
-            t += 0.02;
-            // We use the sine of t as an offset, this way we get a nice smooth animation
-            let x_off = t.sin() * 0.5;
-
-            let shape = vec![
-                Vertex { position: [-0.5 + x_off, -0.5] },
-                Vertex { position: [ 0.0 + x_off,  0.5] },
-                Vertex { position: [ 0.5 + x_off, -0.25] }
-            ];
-            let vertex_buffer = glium::VertexBuffer::new(&display, &shape).unwrap();
-
-            let mut target = display.draw();
-            target.clear_color(0.0, 0.0, 1.0, 1.0);
-            target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
-                    &Default::default()).unwrap();
-            target.finish().unwrap();
-        },
         _ => (),
     };
 });
@@ -125,30 +125,30 @@ Let's remove the two `let`'s that redefine our shape and vertex_buffer from our
 
 ```rust
 let mut t: f32 = 0.0;
-event_loop.run(move |event, _, control_flow| {
+let _ = event_loop.run(move |event, window_target| {
     match event {
         winit::event::Event::WindowEvent { event, .. } => match event {
-            winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
+            winit::event::WindowEvent::CloseRequested => window_target.exit(),
             winit::event::WindowEvent::Resized(window_size) => {
                 display.resize(window_size.into());
             },
+	    winit::event::WindowEvent::RedrawRequested => {
+	        // We update `t`
+	        t += 0.02;
+                // We use the sine of t as an offset, this way we get a nice smooth animation
+	        let x_off = t.sin() * 0.5;
+
+	        let mut target = display.draw();
+	        target.clear_color(0.0, 0.0, 1.0, 1.0);
+	        target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
+			    &Default::default()).unwrap();
+	        target.finish().unwrap();
+	    },
             _ => (),
         },
-        winit::event::Event::RedrawEventsCleared => {
+        winit::event::Event::AboutToWait => {
             window.request_redraw();
         },
-        winit::event::Event::RedrawRequested(_) => {
-            // We update `t`
-            t += 0.02;
-            // We use the sine of t as an offset, this way we get a nice smooth animation
-            let x = t.sin() * 0.5;
-
-            let mut target = display.draw();
-            target.clear_color(0.0, 0.0, 1.0, 1.0);
-            target.draw(&vertex_buffer, &indices, &program, &glium::uniforms::EmptyUniforms,
-                    &Default::default()).unwrap();
-            target.finish().unwrap();
-        },
         _ => (),
     };
 });
@@ -175,7 +175,7 @@ let vertex_shader_src = r#"
 You may notice that this is exactly the operation that we've been doing above, except that this time it is done on the GPU side. We have added a variable `t` in our shader, which is declared as a **uniform**. A uniform is a global variable whose value is set when we draw by passing its value to the `draw` function. The easiest way to do so is to use the `uniform!` macro:
 
 ```rust
-target.draw(&vertex_buffer, &indices, &program, &uniform! { x: x },
+target.draw(&vertex_buffer, &indices, &program, &uniform! { x: x_off },
             &Default::default()).unwrap();
 ```
 
diff --git a/book/tuto-04-matrices.md b/book/tuto-04-matrices.md
index e7d54a19e3..7527485ce0 100644
--- a/book/tuto-04-matrices.md
+++ b/book/tuto-04-matrices.md
@@ -17,7 +17,7 @@ Let's get back to our moving triangle. We are going to change the vertex shader
 
 ```rust
 let vertex_shader_src = r#"
-    ##version 140
+    #version 140
 
     in vec2 position;
 
diff --git a/book/tuto-06-texture.md b/book/tuto-06-texture.md
index 4d21467cdc..30cf8fd2c7 100644
--- a/book/tuto-06-texture.md
+++ b/book/tuto-06-texture.md
@@ -22,7 +22,7 @@ let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw()
 And in order to upload the image as a texture, it's as simple as:
 
 ```rust
-let texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
+let texture = glium::texture::Texture2d::new(&display, image).unwrap();
 ```
 
 # Using the texture
@@ -97,7 +97,7 @@ let uniforms = uniform! {
         [1.0, 0.0, 0.0, 0.0],
         [0.0, 1.0, 0.0, 0.0],
         [0.0, 0.0, 1.0, 0.0],
-        [ t , 0.0, 0.0, 1.0f32],
+        [ x , 0.0, 0.0, 1.0f32],
     ],
     tex: &texture,
 };
diff --git a/book/tuto-14-wall.md b/book/tuto-14-wall.md
index 6d7ac0a973..7c1f505fad 100644
--- a/book/tuto-14-wall.md
+++ b/book/tuto-14-wall.md
@@ -54,7 +54,7 @@ let image = image::load(Cursor::new(&include_bytes!("../book/tuto-14-diffuse.jpg
                         image::JPEG).unwrap().to_rgba8();
 let image_dimensions = image.dimensions();
 let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
-let diffuse_texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
+let diffuse_texture = glium::texture::Texture2d::new(&display, image).unwrap();
 ```
 
 Adding the texture coordinates is also very easy:
diff --git a/examples/tutorial-14.rs b/examples/tutorial-14.rs
index a0390aa022..05dcb09e6b 100644
--- a/examples/tutorial-14.rs
+++ b/examples/tutorial-14.rs
@@ -31,7 +31,7 @@ fn main() {
                             image::ImageFormat::Jpeg).unwrap().to_rgba8();
     let image_dimensions = image.dimensions();
     let image = glium::texture::RawImage2d::from_raw_rgba_reversed(&image.into_raw(), image_dimensions);
-    let diffuse_texture = glium::texture::SrgbTexture2d::new(&display, image).unwrap();
+    let diffuse_texture = glium::texture::Texture2d::new(&display, image).unwrap();
 
     let image = image::load(std::io::Cursor::new(&include_bytes!("../book/resources/tuto-14-normal.png")),
                             image::ImageFormat::Png).unwrap().to_rgba8();
diff --git a/src/lib.rs b/src/lib.rs
index f83cdbf741..32afa5d2cb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,7 +16,7 @@ extern crate winit;
 
 fn main() {
     // 1. The **winit::EventLoop** for handling events.
-    let event_loop = winit::event_loop::EventLoopBuilder::new().build();
+    let event_loop = winit::event_loop::EventLoopBuilder::new().build().unwrap();
     // 2. Create a glutin context and glium Display
     let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
 }


Test patch: