1use graphics::{ellipse, image, text, Transformed};
2use graphics_buffer::*;
3use piston_window::{
4 clear, Event, Loop, PistonWindow, TextureSettings, UpdateArgs, WindowSettings,
5};
6
7fn main() {
8 let matt = RenderBuffer::decode_from_bytes(include_bytes!("matt.jpg")).unwrap();
10
11 let mut glyphs = buffer_glyphs_from_bytes(include_bytes!("roboto.ttf")).unwrap();
13
14 let mut buffer = RenderBuffer::new(matt.width(), matt.height());
16 buffer.clear([0.0, 0.0, 0.0, 1.0]);
17
18 image(&matt, IDENTITY, &mut buffer);
20
21 const RED: [f32; 4] = [1.0, 0.0, 0.0, 0.7];
23 const DIAMETER: f64 = 40.0;
24 ellipse(
25 RED,
26 [115.0, 175.0, DIAMETER, DIAMETER],
27 IDENTITY,
28 &mut buffer,
29 );
30 ellipse(
31 RED,
32 [210.0, 195.0, DIAMETER, DIAMETER],
33 IDENTITY,
34 &mut buffer,
35 );
36
37 text(
39 [0.0, 1.0, 0.0, 1.0],
40 70,
41 "# w o k e",
42 &mut glyphs,
43 IDENTITY.trans(0.0, 70.0),
44 &mut buffer,
45 )
46 .unwrap();
47
48 let mut window: PistonWindow = WindowSettings::new(
50 "piston_window texture example",
51 (matt.height(), matt.height()),
52 )
53 .exit_on_esc(true)
54 .build()
55 .unwrap();
56
57 let matt_texture = buffer
59 .to_g2d_texture(
60 &mut window.create_texture_context(),
61 &TextureSettings::new(),
62 )
63 .unwrap();
64
65 let mut rot = 0.0;
67
68 while let Some(event) = window.next() {
70 match event {
71 Event::Loop(Loop::Render(..)) => {
72 window.draw_2d(&event, |context, graphics, _| {
73 clear([0.0, 0.0, 0.0, 1.0], graphics);
75 image(
77 &matt_texture,
78 context
79 .transform
80 .trans(matt.height() as f64 / 2.0, matt.height() as f64 / 2.0)
81 .scale(0.5, 0.5)
82 .rot_rad(rot),
83 graphics,
84 );
85 });
86 }
87 Event::Loop(Loop::Update(UpdateArgs { dt, .. })) => rot += dt,
89 _ => (),
90 }
91 }
92
93 buffer.save("red_eyes.png").unwrap();
95}