Created
March 23, 2018 19:48
-
-
Save 0e4ef622/d69f32e4b9d2118b0ed27ad16fbfd985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate texture; | |
extern crate glutin_window; | |
extern crate graphics; | |
extern crate opengl_graphics; | |
use opengl_graphics::Texture; | |
use graphics::image::Image; | |
use texture::TextureSettings; | |
fn main() { | |
use piston::window::WindowSettings; | |
use piston::event_loop::{ Events, EventSettings }; | |
use piston::input::RenderEvent; | |
use glutin_window::GlutinWindow as Window; | |
use opengl_graphics::{ OpenGL, GlGraphics }; | |
use graphics::draw_state::DrawState; | |
let opengl = OpenGL::V3_2; | |
let mut window: Window = WindowSettings::new("test", [1024, 768]) | |
.opengl(opengl) | |
.resizable(false) | |
.srgb(false) | |
.build() | |
.expect("Could not create window"); | |
let mut gl = GlGraphics::new(opengl); | |
let draw_state = DrawState::default(); | |
let t = TextureSettings::new(); | |
let texture = Texture::from_path("test.png", &t).unwrap(); | |
let mut events = Events::new(EventSettings::new()); | |
while let Some(e) = events.next(&mut window) { | |
if let Some(r) = e.render_args() { | |
gl.draw(r.viewport(), |c, gl| { | |
graphics::clear([0.0, 0.0, 0.0, 1.0], gl); | |
let img = Image::new().rect([50.0, 50.0, 47.0 * 5.0, 137.0 * 5.0]); | |
img.draw(&texture, &draw_state, c.transform, gl); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment