pub struct GliumWindow<W = GlutinWindow> {
    pub window: Rc<RefCell<W>>,
    pub context: Rc<Context>,
    pub events: Events,
}
Expand description

A window struct for glium.

Fields§

§window: Rc<RefCell<W>>

Window.

§context: Rc<Context>

Glium context.

§events: Events

Event loop state.

Implementations§

source§

impl<W> GliumWindow<W>where W: OpenGLWindow + 'static,

source

pub fn new(window: &Rc<RefCell<W>>) -> Result<Self, IncompatibleOpenGl>

Creates new GliumWindow.

source

pub fn draw(&self) -> Frame

Returns new frame.

Examples found in repository?
examples/text_test.rs (line 31)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() {
    let opengl = OpenGL::V3_2;
    let size = [500, 300];
    let ref mut window: GliumWindow = WindowSettings::new("gfx_graphics: text_test", size)
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let mut glyph_cache = GlyphCache::new(
        Path::new("assets/FiraSans-Regular.ttf"),
        window.clone(),
        TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        if let Some(args) = e.render_args() {
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                use graphics::*;

                clear([1.0; 4], g);
                text::Text::new_color([0.0, 0.5, 0.0, 1.0], 32)
                    .draw(
                        "Hello glium_graphics!",
                        &mut glyph_cache,
                        &DrawState::default(),
                        c.transform.trans(10.0, 100.0),
                        g,
                    )
                    .unwrap();
            });
            target.finish().unwrap();
        }
    }
}
More examples
Hide additional examples
examples/image_test.rs (line 35)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
fn main() {
    let opengl = OpenGL::V3_2;
    let (w, h) = (300, 300);
    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: image_test", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let rust_logo = Texture::from_path(
        window,
        "assets/rust.png",
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        use graphics::*;

        if let Some(args) = e.render_args() {
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                clear(color::WHITE, g);
                rectangle(
                    [1.0, 0.0, 0.0, 1.0],
                    [0.0, 0.0, 100.0, 100.0],
                    c.transform,
                    g,
                );
                rectangle(
                    [0.0, 1.0, 0.0, 0.3],
                    [50.0, 50.0, 100.0, 100.0],
                    c.transform,
                    g,
                );
                image(&rust_logo, c.transform.trans(100.0, 100.0), g);
            });
            target.finish().unwrap();
        }
    }
}
examples/colored_image_test.rs (line 35)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
    let opengl = OpenGL::V3_2;
    let (w, h) = (300, 300);
    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: colored_image_test", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let rust_logo = Texture::from_path(
        window,
        "assets/rust-white.png",
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        use graphics::*;

        if let Some(args) = e.render_args() {
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                use graphics::triangulation::{tx, ty};

                let transform = c.transform.trans(0.0, 0.0);

                let tr = |p: [f64; 2]| [tx(transform, p[0], p[1]), ty(transform, p[0], p[1])];

                clear(color::WHITE, g);
                Rectangle::new([1.0, 0.0, 0.0, 1.0])
                    .draw([0.0, 0.0, 100.0, 100.0], &c.draw_state, c.transform, g);
                Rectangle::new([0.0, 1.0, 0.0, 0.3])
                    .draw([50.0, 50.0, 100.0, 100.0], &c.draw_state, c.transform, g);
                g.tri_list_uv_c(&c.draw_state, &rust_logo, |f| {
                    (f)(
                        &[
                            tr([0.0, 0.0]),
                            tr([300.0, 0.0]),
                            tr([0.0, 300.0]),

                            tr([300.0, 0.0]),
                            tr([0.0, 300.0]),
                            tr([300.0, 300.0]),
                        ],
                        &[
                            [0.0, 0.0],
                            [1.0, 0.0],
                            [0.0, 1.0],

                            [1.0, 0.0],
                            [0.0, 1.0],
                            [1.0, 1.0],
                        ],
                        &[
                            [1.0, 0.0, 0.0, 1.0],
                            [0.0, 1.0, 0.0, 1.0],
                            [0.0, 0.0, 1.0, 1.0],

                            [0.0, 00.0, 0.0, 1.0],
                            [0.0, 00.0, 0.0, 1.0],
                            [0.0, 00.0, 0.0, 1.0],
                        ]
                    )
                });
            });
            target.finish().unwrap();
        }
    }
}
examples/texture_wrap.rs (line 49)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
fn main() {
    println!("Press U to change the texture wrap mode for the u coordinate");
    println!("Press V to change the texture wrap mode for the v coordinate");

    let opengl = OpenGL::V3_2;
    let (w, h) = (600, 600);
    let mut window: GliumWindow = WindowSettings::new("glium_graphics: texture_wrap", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();
    window.set_lazy(true);

    // Set up wrap modes
    let wrap_modes = [
        Wrap::ClampToEdge,
        Wrap::ClampToBorder,
        Wrap::Repeat,
        Wrap::MirroredRepeat,
    ];
    let mut ix_u = 0;
    let mut ix_v = 0;
    let mut texture_settings = TextureSettings::new();
    texture_settings.set_border_color([0.0, 0.0, 0.0, 1.0]);

    let mut rust_logo = Texture::from_path(
        &mut window,
        "assets/rust.png",
        Flip::None,
        &texture_settings,
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, &mut window);
    while let Some(e) = window.next() {
        if let Some(args) = e.render_args() {
            use graphics::*;
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |_c, g| {
                clear([1.0; 4], g);
                let points = [[0.5, 0.5], [-0.5, 0.5], [-0.5, -0.5], [0.5, -0.5]];
                // (0, 1, 2) and (0, 2, 3)
                let uvs = [
                    [4.0, 0.0],
                    [0.0, 0.0],
                    [0.0, 4.0],
                    [4.0, 0.0],
                    [0.0, 4.0],
                    [4.0, 4.0],
                ];
                let mut verts = [[0.0, 0.0]; 6];
                let indices_points: [usize; 6] = [0, 1, 2, 0, 2, 3];
                for (ixv, &ixp) in (0..6).zip((&indices_points).into_iter()) {
                    verts[ixv] = points[ixp];
                }
                g.tri_list_uv(&DrawState::new_alpha(), &[1.0; 4], &rust_logo, |f| {
                    f(&verts, &uvs)
                });
            });
            target.finish().unwrap();
        }

        if let Some(Button::Keyboard(Key::U)) = e.press_args() {
            ix_u = (ix_u + 1) % wrap_modes.len();
            texture_settings.set_wrap_u(wrap_modes[ix_u]);
            rust_logo = Texture::from_path(
                &mut window,
                "assets/rust.png",
                Flip::None,
                &texture_settings,
            )
            .unwrap();
            println!(
                "Changed texture wrap mode for u coordinate to: {:?}",
                wrap_modes[ix_u]
            );
        }

        if let Some(Button::Keyboard(Key::V)) = e.press_args() {
            ix_v = (ix_v + 1) % wrap_modes.len();
            texture_settings.set_wrap_v(wrap_modes[ix_v]);
            rust_logo = Texture::from_path(
                &mut window,
                "assets/rust.png",
                Flip::None,
                &texture_settings,
            )
            .unwrap();
            println!(
                "Changed texture wrap mode for v coordinate to: {:?}",
                wrap_modes[ix_v]
            );
        }
    }
}
examples/draw_state.rs (line 39)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
fn main() {
    println!("Press A to change blending");
    println!("Press S to change clip inside/out");

    let opengl = OpenGL::V3_2;
    let (w, h) = (640, 480);
    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: image_test", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let mut blend = Blend::Alpha;
    let mut clip_inside = true;
    let rust_logo = Texture::from_path(
        window,
        "assets/rust.png",
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        if let Some(args) = e.render_args() {
            use graphics::*;

            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                clear([0.8, 0.8, 0.8, 1.0], g);
                g.clear_stencil(0);
                Rectangle::new([1.0, 0.0, 0.0, 1.0]).draw(
                    [0.0, 0.0, 100.0, 100.0],
                    &c.draw_state,
                    c.transform,
                    g,
                );

                let draw_state = c.draw_state.blend(blend);
                Rectangle::new([0.5, 1.0, 0.0, 0.3]).draw(
                    [50.0, 50.0, 100.0, 100.0],
                    &draw_state,
                    c.transform,
                    g,
                );

                let transform = c.transform.trans(100.0, 100.0);
                // Compute clip rectangle from upper left corner.
                let (clip_x, clip_y, clip_w, clip_h) = (100, 100, 100, 100);
                let (clip_x, clip_y, clip_w, clip_h) = (
                    clip_x,
                    c.viewport.unwrap().draw_size[1] - clip_y - clip_h,
                    clip_w,
                    clip_h,
                );
                let clipped = c.draw_state.scissor([clip_x, clip_y, clip_w, clip_h]);
                Image::new().draw(&rust_logo, &clipped, transform, g);

                let transform = c.transform.trans(200.0, 200.0);
                Ellipse::new([1.0, 0.0, 0.0, 1.0]).draw(
                    [0.0, 0.0, 50.0, 50.0],
                    &DrawState::new_clip(),
                    transform,
                    g,
                );
                Image::new().draw(
                    &rust_logo,
                    &(if clip_inside {
                        DrawState::new_inside()
                    } else {
                        DrawState::new_outside()
                    }),
                    transform,
                    g,
                );
            });

            target.finish().unwrap();
        }

        if let Some(Button::Keyboard(Key::A)) = e.press_args() {
            blend = match blend {
                Blend::Alpha => Blend::Add,
                Blend::Add => Blend::Multiply,
                Blend::Multiply => Blend::Invert,
                Blend::Invert => Blend::Lighter,
                Blend::Lighter => Blend::Alpha,
            };
            println!("Changed blending to {:?}", blend);
        }

        if let Some(Button::Keyboard(Key::S)) = e.press_args() {
            clip_inside = !clip_inside;
            if clip_inside {
                println!("Changed to clip inside");
            } else {
                println!("Changed to clip outside");
            }
        }
    }
}
source

pub fn next(&mut self) -> Option<Event>

Returns next event.

Examples found in repository?
examples/text_test.rs (line 29)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
fn main() {
    let opengl = OpenGL::V3_2;
    let size = [500, 300];
    let ref mut window: GliumWindow = WindowSettings::new("gfx_graphics: text_test", size)
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let mut glyph_cache = GlyphCache::new(
        Path::new("assets/FiraSans-Regular.ttf"),
        window.clone(),
        TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        if let Some(args) = e.render_args() {
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                use graphics::*;

                clear([1.0; 4], g);
                text::Text::new_color([0.0, 0.5, 0.0, 1.0], 32)
                    .draw(
                        "Hello glium_graphics!",
                        &mut glyph_cache,
                        &DrawState::default(),
                        c.transform.trans(10.0, 100.0),
                        g,
                    )
                    .unwrap();
            });
            target.finish().unwrap();
        }
    }
}
More examples
Hide additional examples
examples/image_test.rs (line 31)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
fn main() {
    let opengl = OpenGL::V3_2;
    let (w, h) = (300, 300);
    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: image_test", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let rust_logo = Texture::from_path(
        window,
        "assets/rust.png",
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        use graphics::*;

        if let Some(args) = e.render_args() {
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                clear(color::WHITE, g);
                rectangle(
                    [1.0, 0.0, 0.0, 1.0],
                    [0.0, 0.0, 100.0, 100.0],
                    c.transform,
                    g,
                );
                rectangle(
                    [0.0, 1.0, 0.0, 0.3],
                    [50.0, 50.0, 100.0, 100.0],
                    c.transform,
                    g,
                );
                image(&rust_logo, c.transform.trans(100.0, 100.0), g);
            });
            target.finish().unwrap();
        }
    }
}
examples/colored_image_test.rs (line 31)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
fn main() {
    let opengl = OpenGL::V3_2;
    let (w, h) = (300, 300);
    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: colored_image_test", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let rust_logo = Texture::from_path(
        window,
        "assets/rust-white.png",
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        use graphics::*;

        if let Some(args) = e.render_args() {
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                use graphics::triangulation::{tx, ty};

                let transform = c.transform.trans(0.0, 0.0);

                let tr = |p: [f64; 2]| [tx(transform, p[0], p[1]), ty(transform, p[0], p[1])];

                clear(color::WHITE, g);
                Rectangle::new([1.0, 0.0, 0.0, 1.0])
                    .draw([0.0, 0.0, 100.0, 100.0], &c.draw_state, c.transform, g);
                Rectangle::new([0.0, 1.0, 0.0, 0.3])
                    .draw([50.0, 50.0, 100.0, 100.0], &c.draw_state, c.transform, g);
                g.tri_list_uv_c(&c.draw_state, &rust_logo, |f| {
                    (f)(
                        &[
                            tr([0.0, 0.0]),
                            tr([300.0, 0.0]),
                            tr([0.0, 300.0]),

                            tr([300.0, 0.0]),
                            tr([0.0, 300.0]),
                            tr([300.0, 300.0]),
                        ],
                        &[
                            [0.0, 0.0],
                            [1.0, 0.0],
                            [0.0, 1.0],

                            [1.0, 0.0],
                            [0.0, 1.0],
                            [1.0, 1.0],
                        ],
                        &[
                            [1.0, 0.0, 0.0, 1.0],
                            [0.0, 1.0, 0.0, 1.0],
                            [0.0, 0.0, 1.0, 1.0],

                            [0.0, 00.0, 0.0, 1.0],
                            [0.0, 00.0, 0.0, 1.0],
                            [0.0, 00.0, 0.0, 1.0],
                        ]
                    )
                });
            });
            target.finish().unwrap();
        }
    }
}
examples/texture_wrap.rs (line 46)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
fn main() {
    println!("Press U to change the texture wrap mode for the u coordinate");
    println!("Press V to change the texture wrap mode for the v coordinate");

    let opengl = OpenGL::V3_2;
    let (w, h) = (600, 600);
    let mut window: GliumWindow = WindowSettings::new("glium_graphics: texture_wrap", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();
    window.set_lazy(true);

    // Set up wrap modes
    let wrap_modes = [
        Wrap::ClampToEdge,
        Wrap::ClampToBorder,
        Wrap::Repeat,
        Wrap::MirroredRepeat,
    ];
    let mut ix_u = 0;
    let mut ix_v = 0;
    let mut texture_settings = TextureSettings::new();
    texture_settings.set_border_color([0.0, 0.0, 0.0, 1.0]);

    let mut rust_logo = Texture::from_path(
        &mut window,
        "assets/rust.png",
        Flip::None,
        &texture_settings,
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, &mut window);
    while let Some(e) = window.next() {
        if let Some(args) = e.render_args() {
            use graphics::*;
            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |_c, g| {
                clear([1.0; 4], g);
                let points = [[0.5, 0.5], [-0.5, 0.5], [-0.5, -0.5], [0.5, -0.5]];
                // (0, 1, 2) and (0, 2, 3)
                let uvs = [
                    [4.0, 0.0],
                    [0.0, 0.0],
                    [0.0, 4.0],
                    [4.0, 0.0],
                    [0.0, 4.0],
                    [4.0, 4.0],
                ];
                let mut verts = [[0.0, 0.0]; 6];
                let indices_points: [usize; 6] = [0, 1, 2, 0, 2, 3];
                for (ixv, &ixp) in (0..6).zip((&indices_points).into_iter()) {
                    verts[ixv] = points[ixp];
                }
                g.tri_list_uv(&DrawState::new_alpha(), &[1.0; 4], &rust_logo, |f| {
                    f(&verts, &uvs)
                });
            });
            target.finish().unwrap();
        }

        if let Some(Button::Keyboard(Key::U)) = e.press_args() {
            ix_u = (ix_u + 1) % wrap_modes.len();
            texture_settings.set_wrap_u(wrap_modes[ix_u]);
            rust_logo = Texture::from_path(
                &mut window,
                "assets/rust.png",
                Flip::None,
                &texture_settings,
            )
            .unwrap();
            println!(
                "Changed texture wrap mode for u coordinate to: {:?}",
                wrap_modes[ix_u]
            );
        }

        if let Some(Button::Keyboard(Key::V)) = e.press_args() {
            ix_v = (ix_v + 1) % wrap_modes.len();
            texture_settings.set_wrap_v(wrap_modes[ix_v]);
            rust_logo = Texture::from_path(
                &mut window,
                "assets/rust.png",
                Flip::None,
                &texture_settings,
            )
            .unwrap();
            println!(
                "Changed texture wrap mode for v coordinate to: {:?}",
                wrap_modes[ix_v]
            );
        }
    }
}
examples/draw_state.rs (line 35)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
fn main() {
    println!("Press A to change blending");
    println!("Press S to change clip inside/out");

    let opengl = OpenGL::V3_2;
    let (w, h) = (640, 480);
    let ref mut window: GliumWindow = WindowSettings::new("glium_graphics: image_test", [w, h])
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();

    let mut blend = Blend::Alpha;
    let mut clip_inside = true;
    let rust_logo = Texture::from_path(
        window,
        "assets/rust.png",
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    let mut g2d = Glium2d::new(opengl, window);
    window.set_lazy(true);
    while let Some(e) = window.next() {
        if let Some(args) = e.render_args() {
            use graphics::*;

            let mut target = window.draw();
            g2d.draw(&mut target, args.viewport(), |c, g| {
                clear([0.8, 0.8, 0.8, 1.0], g);
                g.clear_stencil(0);
                Rectangle::new([1.0, 0.0, 0.0, 1.0]).draw(
                    [0.0, 0.0, 100.0, 100.0],
                    &c.draw_state,
                    c.transform,
                    g,
                );

                let draw_state = c.draw_state.blend(blend);
                Rectangle::new([0.5, 1.0, 0.0, 0.3]).draw(
                    [50.0, 50.0, 100.0, 100.0],
                    &draw_state,
                    c.transform,
                    g,
                );

                let transform = c.transform.trans(100.0, 100.0);
                // Compute clip rectangle from upper left corner.
                let (clip_x, clip_y, clip_w, clip_h) = (100, 100, 100, 100);
                let (clip_x, clip_y, clip_w, clip_h) = (
                    clip_x,
                    c.viewport.unwrap().draw_size[1] - clip_y - clip_h,
                    clip_w,
                    clip_h,
                );
                let clipped = c.draw_state.scissor([clip_x, clip_y, clip_w, clip_h]);
                Image::new().draw(&rust_logo, &clipped, transform, g);

                let transform = c.transform.trans(200.0, 200.0);
                Ellipse::new([1.0, 0.0, 0.0, 1.0]).draw(
                    [0.0, 0.0, 50.0, 50.0],
                    &DrawState::new_clip(),
                    transform,
                    g,
                );
                Image::new().draw(
                    &rust_logo,
                    &(if clip_inside {
                        DrawState::new_inside()
                    } else {
                        DrawState::new_outside()
                    }),
                    transform,
                    g,
                );
            });

            target.finish().unwrap();
        }

        if let Some(Button::Keyboard(Key::A)) = e.press_args() {
            blend = match blend {
                Blend::Alpha => Blend::Add,
                Blend::Add => Blend::Multiply,
                Blend::Multiply => Blend::Invert,
                Blend::Invert => Blend::Lighter,
                Blend::Lighter => Blend::Alpha,
            };
            println!("Changed blending to {:?}", blend);
        }

        if let Some(Button::Keyboard(Key::S)) = e.press_args() {
            clip_inside = !clip_inside;
            if clip_inside {
                println!("Changed to clip inside");
            } else {
                println!("Changed to clip outside");
            }
        }
    }
}

Methods from Deref<Target = Context>§

source

pub fn get_framebuffer_dimensions(&self) -> (u32, u32)

Calls get_framebuffer_dimensions on the backend object stored by this context.

source

pub unsafe fn rebuild<B>(&self, new_backend: B) -> Result<(), IncompatibleOpenGl>where B: Backend + 'static,

Changes the OpenGL context associated with this context.

The new context must have lists shared with the old one.

source

pub fn swap_buffers(&self) -> Result<(), SwapBuffersError>

Swaps the buffers in the backend.

source

pub fn get_version(&self) -> &Version

👎Deprecated: use get_opengl_version instead.

Returns the OpenGL version

source

pub fn get_opengl_version(&self) -> &Version

Returns the OpenGL version detected by this context.

source

pub fn get_supported_glsl_version(&self) -> Version

Returns the GLSL version guaranteed to be supported.

source

pub fn is_glsl_version_supported(&self, version: &Version) -> bool

Returns true if the given GLSL version is supported.

source

pub fn get_opengl_version_string(&self) -> &str

Returns a string containing this GL version or release number used by this context.

Vendor-specific information may follow the version number.

source

pub fn get_opengl_vendor_string(&self) -> &str

Returns a string containing the company responsible for this GL implementation.

source

pub fn get_opengl_renderer_string(&self) -> &str

Returns a string containing the name of the GL renderer used by this context.

This name is typically specific to a particular configuration of a hardware platform.

source

pub fn is_debug(&self) -> bool

Returns true if the context is in debug mode.

Debug mode may provide additional error and performance issue reporting functionality.

source

pub fn is_forward_compatible(&self) -> bool

Returns true if the context is in “forward-compatible” mode.

Forward-compatible mode means that no deprecated functionality will be supported.

source

pub fn get_opengl_profile(&self) -> Option<Profile>

Returns this context’s OpenGL profile if available.

The context profile is available from OpenGL 3.2 onwards. Returns None if not supported.

source

pub fn is_robust(&self) -> bool

Returns true if out-of-bound buffer access from the GPU side (inside a program) cannot result in a crash.

You should take extra care if is_robust returns false.

source

pub fn is_context_loss_possible(&self) -> bool

Returns true if a context loss is possible.

source

pub fn is_context_lost(&self) -> bool

Returns true if the context has been lost and needs to be recreated.

Implementation

If it has been determined that the context has been lost before, then the function immediately returns true. Otherwise, calls glGetGraphicsResetStatus. If this function is not available, returns false.

source

pub fn get_release_behavior(&self) -> ReleaseBehavior

Returns the behavior when the current OpenGL context is changed.

The most common value is Flush. In order to get None you must explicitly request it during creation.

source

pub fn get_max_anisotropy_support(&self) -> Option<u16>

Returns the maximum value that can be used for anisotropic filtering, or None if the hardware doesn’t support it.

source

pub fn get_max_viewport_dimensions(&self) -> (u32, u32)

Returns the maximum dimensions of the viewport.

Glium will panic if you request a larger viewport than this when drawing.

source

pub fn release_shader_compiler(&self)

Releases the shader compiler, indicating that no new programs will be created for a while.

This method is a no-op if it’s not available in the implementation.

source

pub fn get_free_video_memory(&self) -> Option<usize>

Returns an estimate of the amount of video memory available in bytes.

Returns None if no estimate is available.

source

pub fn read_front_buffer<T>(&self) -> Result<T, ReadError>where T: Texture2dDataSink<(u8, u8, u8, u8)>,

Reads the content of the front buffer.

You will only see the data that has finished being drawn.

This function can return any type that implements Texture2dDataSink<(u8, u8, u8, u8)>.

Example
let pixels: Vec<Vec<(u8, u8, u8, u8)>> = display.read_front_buffer();
source

pub unsafe fn exec_in_context<'a, T, F>(&self, action: F) -> Twhere T: Send + 'static, F: FnOnce() -> T + 'a,

Execute an arbitrary closure with the OpenGL context active. Useful if another component needs to directly manipulate OpenGL state.

If action manipulates any OpenGL state, it must be restored before action completes.

source

pub fn assert_no_error(&self, user_msg: Option<&str>)

Asserts that there are no OpenGL errors pending.

This function should be used in tests.

source

pub fn synchronize(&self)

DEPRECATED. Renamed finish.

source

pub fn finish(&self)

Calls glFinish(). This waits until all the previously issued commands have finished being executed.

When you execute OpenGL functions, they are not executed immediately. Instead they are put in a queue. This function flushes this queue, then waits until all commands have finished being executed.

You normally don’t need to call this function manually, except for debugging purposes.

source

pub fn flush(&self)

Calls glFlush(). This starts executing the commands that you have issued if it is not yet the case.

When you execute OpenGL functions, they are not executed immediately. Instead they are put in a queue. This function flushes this queue so that commands start being executed.

You normally don’t need to call this function manually. Swapping buffers automatically flushes the queue. This function can be useful if you want to benchmark the time it takes from your OpenGL driver to process commands.

source

pub fn insert_debug_marker(&self, marker: &str) -> Result<(), ()>

Inserts a debugging string in the commands queue. If you use an OpenGL debugger, you will be able to see that string.

This is helpful to understand where you are when you have big applications.

Returns Err if the backend doesn’t support this functionality. You can choose whether to call .unwrap() if you want to make sure that it works, or .ok() if you don’t care.

source

pub fn debug_insert_debug_marker(&self, marker: &str) -> Result<(), ()>

Same as insert_debug_marker, except that if you don’t compile with debug_assertions it is a no-op and returns Ok.

Trait Implementations§

source§

impl<W> AdvancedWindow for GliumWindow<W>where W: AdvancedWindow,

source§

fn get_title(&self) -> String

Gets a copy of the title of the window.
source§

fn set_title(&mut self, title: String)

Sets the title of the window.
source§

fn get_automatic_close(&self) -> bool

Gets whether the window will automatically close when attempting to close it. Read more
source§

fn set_automatic_close(&mut self, value: bool)

Sets whether the window will automatically close when attempting to close it. If this is disabled, attempts to close the window can be detected via an Input::Close(..) event, and Window::set_should_close() can be called to actually close the window. Read more
source§

fn get_exit_on_esc(&self) -> bool

Gets whether to exit when pressing esc. Read more
source§

fn set_exit_on_esc(&mut self, value: bool)

Sets whether to exit when pressing esc. Read more
source§

fn set_capture_cursor(&mut self, value: bool)

Sets whether to capture/grab the cursor. Read more
source§

fn show(&mut self)

Shows the window. Read more
source§

fn hide(&mut self)

Hides the window. Read more
source§

fn get_position(&self) -> Option<Position>

Gets the position of window.
source§

fn set_position<P: Into<Position>>(&mut self, pos: P)

Sets the position of window. Read more
source§

fn set_size<S: Into<Size>>(&mut self, size: S)

Sets the window size. Read more
§

fn title(self, value: String) -> Self

Sets title on window. Read more
§

fn exit_on_esc(self, value: bool) -> Self

Sets whether to exit when pressing the Esc button. Read more
§

fn automatic_close(self, value: bool) -> Self

Sets whether the window will automatically close when attempting to close it. If this is disabled, attempts to close the window can be detected via an Input::Close(..) event, and Window::set_should_close() can be called to actually close the window. Read more
§

fn capture_cursor(self, value: bool) -> Self

Sets whether to capture/grab the cursor. Read more
§

fn position<P>(self, val: P) -> Selfwhere P: Into<Position>,

Sets the position of window. Read more
source§

impl<W> BuildFromWindowSettings for GliumWindow<W>where W: 'static + Window + OpenGLWindow + BuildFromWindowSettings,

source§

fn build_from_window_settings( settings: &WindowSettings ) -> Result<GliumWindow<W>, Box<dyn Error>>

Builds the window from a WindowSettings object. Read more
source§

impl<W> Clone for GliumWindow<W>

source§

fn clone(&self) -> GliumWindow<W>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<W> Deref for GliumWindow<W>

§

type Target = Context

The resulting type after dereferencing.
source§

fn deref(&self) -> &Context

Dereferences the value.
source§

impl<W> EventLoop for GliumWindow<W>

source§

fn get_event_settings(&self) -> EventSettings

Returns event loop settings.
source§

fn set_event_settings(&mut self, settings: EventSettings)

Sets event loop settings.
§

fn set_ups(&mut self, frames: u64)

The number of updates per second Read more
§

fn ups(self, frames: u64) -> Self

The number of updates per second Read more
§

fn set_ups_reset(&mut self, frames: u64)

The number of delayed updates before skipping them to catch up. When set to 0, it will always try to catch up.
§

fn ups_reset(self, frames: u64) -> Self

The number of delayed updates before skipping them to catch up. When set to 0, it will always try to catch up.
§

fn set_max_fps(&mut self, frames: u64)

The maximum number of frames per second Read more
§

fn max_fps(self, frames: u64) -> Self

The maximum number of frames per second Read more
§

fn set_swap_buffers(&mut self, enable: bool)

Enable or disable automatic swapping of buffers.
§

fn swap_buffers(self, enable: bool) -> Self

Enable or disable automatic swapping of buffers.
§

fn set_bench_mode(&mut self, enable: bool)

Enable or disable benchmark mode. When enabled, it will render and update without sleep and ignore input. Used to test performance by playing through as fast as possible. Requires lazy to be set to false.
§

fn bench_mode(self, enable: bool) -> Self

Enable or disable benchmark mode. When enabled, it will render and update without sleep and ignore input. Used to test performance by playing through as fast as possible. Requires lazy to be set to false.
§

fn set_lazy(&mut self, enable: bool)

Enable or disable rendering only when receiving input. When enabled, update events are disabled. Idle events are emitted while receiving input.
§

fn lazy(self, enable: bool) -> Self

Enable or disable rendering only when receiving input. When enabled, update events are disabled. Idle events are emitted while receiving input.
source§

impl<W> Facade for GliumWindow<W>

source§

fn get_context(&self) -> &Rc<Context>

Returns an opaque type that contains the OpenGL state, extensions, version, etc.
source§

impl<W> Window for GliumWindow<W>where W: Window,

source§

fn should_close(&self) -> bool

Returns true if the window should close.
source§

fn set_should_close(&mut self, value: bool)

Tells the window to close or stay open.
source§

fn size(&self) -> Size

Gets the size of the window.
source§

fn draw_size(&self) -> Size

Gets the draw size of the window. Read more
source§

fn swap_buffers(&mut self)

Swaps render buffers. Read more
source§

fn poll_event(&mut self) -> Option<Event>

Polls an input event from the window. Read more
source§

fn wait_event(&mut self) -> Event

Wait indefinitely for an input event to be available from the window.
source§

fn wait_event_timeout(&mut self, duration: Duration) -> Option<Event>

Wait for an input event to be available from the window or for the specified timeout to be reached. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CapabilitiesSource for Twhere T: Facade + ?Sized,

source§

fn get_version(&self) -> &Version

Returns the version of the backend.
source§

fn get_extensions(&self) -> &ExtensionsList

Returns the list of extensions that are supported.
source§

fn get_capabilities(&self) -> &Capabilities

Returns the capabilities of the backend.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.