1extern crate gust_render as gust;
2
3use gust::prelude::*;
4use gust::vertex::{Vertex, VertexArray};
5use gust::vertex_buffer::{VertexBuffer, Primitive};
6use gust::event::EventType;
7
8fn main() {
9 let mut window = Window::new(gust::WIDTH, gust::HEIGHT, "Hello");
10 let vert_arr = VertexArray::from(
11 vec![
12 Vertex::new(
13 Vector::new(800.0, 400.0),
14 Vector::new(200.0, 0.0),
15 Color::new(0.0, 1.0, 0.0),
16 ),
17 Vertex::new(
18 Vector::new(1200.0, 700.0),
19 Vector::new(20.0, 10.0),
20 Color::new(0.0, 1.0, 1.0),
21 ),
22 Vertex::new(
23 Vector::new(1000.0, 300.0),
24 Vector::new(0.0, 0.0),
25 Color::new(0.0, 0.2, 1.0),
26 ),
27 Vertex::new(
28 Vector::new(800.0, 100.0),
29 Vector::new(0.0, 0.0),
30 Color::new(1.0, 1.0, 0.5),
31 ),
32 Vertex::new(
33 Vector::new(600.0, 300.0),
34 Vector::new(0.0, 0.0),
35 Color::new(0.5, 0.2, 0.1),
36 ),
37 Vertex::new(
38 Vector::new(400.0, 700.0),
39 Vector::new(0.0, 0.0),
40 Color::new(1.0, 0.0, 0.0),
41 ),
42 ]
43 .as_slice(),
44 );
45
46 let vert_arr_2 = VertexArray::from(
47 vec![
48 Vertex::new(Vector::new(0.0, 0.0), Vector::new(0.0, 0.0), Color::blue()),
49 Vertex::new(
50 Vector::new(0.0, 100.0),
51 Vector::new(0.0, 0.0),
52 Color::blue(),
53 ),
54 Vertex::new(
55 Vector::new(100.0, 100.0),
56 Vector::new(0.0, 0.0),
57 Color::blue(),
58 ),
59 Vertex::new(Vector::new(0.0, 0.0), Vector::new(0.0, 0.0), Color::green()),
60 Vertex::new(
61 Vector::new(100.0, 100.0),
62 Vector::new(0.0, 0.0),
63 Color::green(),
64 ),
65 Vertex::new(
66 Vector::new(100.0, 0.0),
67 Vector::new(0.0, 0.0),
68 Color::green(),
69 ),
70 ]
71 .as_slice(),
72 );
73
74 let vert_buf = VertexBuffer::new(Primitive::TriangleFan, vert_arr);
75 let vert_buf2 = VertexBuffer::new(Primitive::Triangles, vert_arr_2);
76
77 let event_handler = EventHandler::new(&window);
78
79 window.set_clear_color(Color::red());
80 window.poll(EventType::Key);
81 while window.is_open() {
82 window.poll_events();
83
84 for event in event_handler.fetch() {
85 match event.1 {
86 Events::Key(Key::Escape, _, Action::Press, _) => {
87 window.close();
88 }
89 _ => {}
90 }
91 }
92
93 window.clear();
94 window.draw(&vert_buf);
95 window.draw(&vert_buf2);
96 window.display();
97 }
98}