image_test/
image_test.rs

1extern crate glium;
2extern crate glium_graphics;
3extern crate graphics;
4extern crate image;
5extern crate piston;
6
7use glium_graphics::{Flip, Glium2d, GliumWindow, OpenGL, Texture, TextureSettings};
8use piston::event_loop::EventLoop;
9use piston::input::RenderEvent;
10use piston::window::WindowSettings;
11
12fn main() {
13    let opengl = OpenGL::V3_2;
14    let (w, h) = (300, 300);
15    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: image_test", [w, h])
16        .exit_on_esc(true)
17        .graphics_api(opengl)
18        .build()
19        .unwrap();
20
21    let rust_logo = Texture::from_path(
22        window,
23        "assets/rust.png",
24        Flip::None,
25        &TextureSettings::new(),
26    )
27    .unwrap();
28
29    let mut g2d = Glium2d::new(opengl, window);
30    window.set_lazy(true);
31    while let Some(e) = window.next() {
32        use graphics::*;
33
34        if let Some(args) = e.render_args() {
35            let mut target = window.draw();
36            g2d.draw(&mut target, args.viewport(), |c, g| {
37                clear(color::WHITE, g);
38                rectangle(
39                    [1.0, 0.0, 0.0, 1.0],
40                    [0.0, 0.0, 100.0, 100.0],
41                    c.transform,
42                    g,
43                );
44                rectangle(
45                    [0.0, 1.0, 0.0, 0.3],
46                    [50.0, 50.0, 100.0, 100.0],
47                    c.transform,
48                    g,
49                );
50                image(&rust_logo, c.transform.trans(100.0, 100.0), g);
51            });
52            target.finish().unwrap();
53        }
54    }
55}