Struct glium_graphics::GliumWindow
source · 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,
impl<W> GliumWindow<W>where W: OpenGLWindow + 'static,
sourcepub fn new(window: &Rc<RefCell<W>>) -> Result<Self, IncompatibleOpenGl>
pub fn new(window: &Rc<RefCell<W>>) -> Result<Self, IncompatibleOpenGl>
Creates new GliumWindow.
sourcepub fn draw(&self) -> Frame
pub fn draw(&self) -> Frame
Returns new frame.
Examples found in repository?
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
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();
}
}
}
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();
}
}
}
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]
);
}
}
}
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");
}
}
}
}
sourcepub fn next(&mut self) -> Option<Event>
pub fn next(&mut self) -> Option<Event>
Returns next event.
Examples found in repository?
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
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();
}
}
}
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();
}
}
}
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]
);
}
}
}
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>§
sourcepub fn get_framebuffer_dimensions(&self) -> (u32, u32)
pub fn get_framebuffer_dimensions(&self) -> (u32, u32)
Calls get_framebuffer_dimensions
on the backend object stored by this context.
sourcepub unsafe fn rebuild<B>(&self, new_backend: B) -> Result<(), IncompatibleOpenGl>where
B: Backend + 'static,
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.
sourcepub fn swap_buffers(&self) -> Result<(), SwapBuffersError>
pub fn swap_buffers(&self) -> Result<(), SwapBuffersError>
Swaps the buffers in the backend.
sourcepub fn get_version(&self) -> &Version
👎Deprecated: use get_opengl_version
instead.
pub fn get_version(&self) -> &Version
get_opengl_version
instead.Returns the OpenGL version
sourcepub fn get_opengl_version(&self) -> &Version
pub fn get_opengl_version(&self) -> &Version
Returns the OpenGL version detected by this context.
sourcepub fn get_supported_glsl_version(&self) -> Version
pub fn get_supported_glsl_version(&self) -> Version
Returns the GLSL version guaranteed to be supported.
sourcepub fn is_glsl_version_supported(&self, version: &Version) -> bool
pub fn is_glsl_version_supported(&self, version: &Version) -> bool
Returns true if the given GLSL version is supported.
sourcepub fn get_opengl_version_string(&self) -> &str
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.
sourcepub fn get_opengl_vendor_string(&self) -> &str
pub fn get_opengl_vendor_string(&self) -> &str
Returns a string containing the company responsible for this GL implementation.
sourcepub fn get_opengl_renderer_string(&self) -> &str
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.
sourcepub fn is_debug(&self) -> bool
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.
sourcepub fn is_forward_compatible(&self) -> bool
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.
sourcepub fn get_opengl_profile(&self) -> Option<Profile>
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.
sourcepub fn is_robust(&self) -> bool
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.
sourcepub fn is_context_loss_possible(&self) -> bool
pub fn is_context_loss_possible(&self) -> bool
Returns true if a context loss is possible.
sourcepub fn is_context_lost(&self) -> bool
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.
sourcepub fn get_release_behavior(&self) -> ReleaseBehavior
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.
sourcepub fn get_max_anisotropy_support(&self) -> Option<u16>
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.
sourcepub fn get_max_viewport_dimensions(&self) -> (u32, u32)
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.
sourcepub fn release_shader_compiler(&self)
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.
sourcepub fn get_free_video_memory(&self) -> Option<usize>
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.
sourcepub fn read_front_buffer<T>(&self) -> Result<T, ReadError>where
T: Texture2dDataSink<(u8, u8, u8, u8)>,
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();
sourcepub unsafe fn exec_in_context<'a, T, F>(&self, action: F) -> Twhere
T: Send + 'static,
F: FnOnce() -> T + 'a,
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.
sourcepub fn assert_no_error(&self, user_msg: Option<&str>)
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.
sourcepub fn synchronize(&self)
pub fn synchronize(&self)
DEPRECATED. Renamed finish
.
sourcepub fn finish(&self)
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.
sourcepub fn flush(&self)
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.
sourcepub fn insert_debug_marker(&self, marker: &str) -> Result<(), ()>
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.
Trait Implementations§
source§impl<W> AdvancedWindow for GliumWindow<W>where
W: AdvancedWindow,
impl<W> AdvancedWindow for GliumWindow<W>where W: AdvancedWindow,
source§fn get_automatic_close(&self) -> bool
fn get_automatic_close(&self) -> bool
source§fn set_automatic_close(&mut self, value: bool)
fn set_automatic_close(&mut self, value: bool)
Input::Close(..)
event, and
Window::set_should_close()
can be called to actually close the window. Read moresource§fn get_exit_on_esc(&self) -> bool
fn get_exit_on_esc(&self) -> bool
source§fn set_exit_on_esc(&mut self, value: bool)
fn set_exit_on_esc(&mut self, value: bool)
source§fn set_capture_cursor(&mut self, value: bool)
fn set_capture_cursor(&mut self, value: bool)
source§fn get_position(&self) -> Option<Position>
fn get_position(&self) -> Option<Position>
source§fn set_position<P: Into<Position>>(&mut self, pos: P)
fn set_position<P: Into<Position>>(&mut self, pos: P)
§fn exit_on_esc(self, value: bool) -> Self
fn exit_on_esc(self, value: bool) -> Self
§fn automatic_close(self, value: bool) -> Self
fn automatic_close(self, value: bool) -> Self
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
fn capture_cursor(self, value: bool) -> Self
source§impl<W> BuildFromWindowSettings for GliumWindow<W>where
W: 'static + Window + OpenGLWindow + BuildFromWindowSettings,
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>>
fn build_from_window_settings( settings: &WindowSettings ) -> Result<GliumWindow<W>, Box<dyn Error>>
WindowSettings
object. Read moresource§impl<W> Clone for GliumWindow<W>
impl<W> Clone for GliumWindow<W>
source§fn clone(&self) -> GliumWindow<W>
fn clone(&self) -> GliumWindow<W>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<W> Deref for GliumWindow<W>
impl<W> Deref for GliumWindow<W>
source§impl<W> EventLoop for GliumWindow<W>
impl<W> EventLoop for GliumWindow<W>
source§fn get_event_settings(&self) -> EventSettings
fn get_event_settings(&self) -> EventSettings
source§fn set_event_settings(&mut self, settings: EventSettings)
fn set_event_settings(&mut self, settings: EventSettings)
§fn set_ups_reset(&mut self, frames: u64)
fn set_ups_reset(&mut self, frames: u64)
0
, it will always try to catch up.§fn ups_reset(self, frames: u64) -> Self
fn ups_reset(self, frames: u64) -> Self
0
, it will always try to catch up.§fn set_max_fps(&mut self, frames: u64)
fn set_max_fps(&mut self, frames: u64)
§fn set_swap_buffers(&mut self, enable: bool)
fn set_swap_buffers(&mut self, enable: bool)
§fn swap_buffers(self, enable: bool) -> Self
fn swap_buffers(self, enable: bool) -> Self
§fn set_bench_mode(&mut self, enable: bool)
fn set_bench_mode(&mut self, enable: bool)
lazy
to be set to false
.§fn bench_mode(self, enable: bool) -> Self
fn bench_mode(self, enable: bool) -> Self
lazy
to be set to false
.