An image
extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;
use piston::window::WindowSettings;
use piston::event::*;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL, Texture};
use graphics::{Image, clear, default_draw_state};
use graphics::rectangle::square;
use std::path::Path;
fn main() {
let opengl = OpenGL::_3_2;
let mut gl = GlGraphics::new(opengl);
let window = Window::new(
opengl,
WindowSettings::new(
"Example",
[600, 400]
).exit_on_esc(true));
let image = Image::new().rect(square(0.0, 0.0, 200.0));
let texture = Texture::from_path(Path::new("Example.png")).unwrap();
for e in window.events() {
if let Some(r) = e.render_args() {
gl.draw(r.viewport(), |c, gl| {
clear([0.0, 0.0, 0.0, 1.0], gl);
image.draw(&texture, default_draw_state(), c.transform, gl);
});
}
}
}
The rectangle to draw image inside
The image source rectangle
Creates a new colored image
Sets optional source rectangle.
Draws image using default method.
Draws image using triangulation.
Performs copy-assignment from source. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from)
Mutably borrows from an owned value. Read more