pub struct WindowedSystem { /* private fields */ }Expand description
A version where the user can control the size of the window.
Implementations§
Source§impl WindowedSystem
impl WindowedSystem
Sourcepub fn new(
dim: [usize; 2],
events_loop: &EventLoop<()>,
title: &str,
) -> WindowedSystem
pub fn new( dim: [usize; 2], events_loop: &EventLoop<()>, title: &str, ) -> WindowedSystem
Examples found in repository?
examples/simple.rs (line 8)
6fn main() {
7 let events_loop = glutin::event_loop::EventLoop::new();
8 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
9
10 //Draw 60 frames per second.
11 let mut timer = egaku2d::RefreshTimer::new(16);
12
13 let mut cursor = [0.0; 2];
14 events_loop.run(move |event, _, control_flow| match event {
15 Event::WindowEvent { event, .. } => match event {
16 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
17 Some(VirtualKeyCode::Escape) => {
18 *control_flow = ControlFlow::Exit;
19 }
20 _ => {}
21 },
22 WindowEvent::CursorMoved {
23 device_id: _,
24 position: p,
25 ..
26 } => {
27 cursor = [p.x as f32, p.y as f32];
28 }
29 WindowEvent::CloseRequested => {
30 *control_flow = ControlFlow::Exit;
31 }
32 WindowEvent::Resized(_dim) => {}
33 _ => {}
34 },
35
36 Event::MainEventsCleared => {
37 if timer.is_ready() {
38 let canvas = sys.canvas_mut();
39
40 canvas.clear_color([0.2; 3]);
41
42 let mut circles = canvas.circles();
43
44 for x in (20..400).step_by(20) {
45 for y in (20..400).step_by(20) {
46 circles.add([
47 cursor[0] + (x as f32) * (cursor[0] * 0.01),
48 cursor[1] + y as f32,
49 ]);
50 }
51 }
52
53 circles
54 .send_and_uniforms(canvas, 10.0)
55 .with_color([1.0, 1.0, 1.0, 1.0])
56 .draw();
57
58 //display what we drew
59 sys.swap_buffers();
60 }
61 }
62 _ => {}
63 });
64}More examples
examples/demo.rs (line 13)
11fn main() {
12 let events_loop = glutin::event_loop::EventLoop::new();
13 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
14 //let mut sys=egaku2d::FullScreenSystem::new(&events_loop);
15
16 //Make a bunch of textures
17 let sky = sys.texture("day_sky.png", [1, 1]).unwrap();
18 let food_tex = sys.texture("food.png", [8, 8]).unwrap();
19 let adventurer = sys.texture("adventurer.png", [7, 11]).unwrap();
20 let ascii_tex = sys.texture("ascii.png", [16, 14]).unwrap();
21 let tall_tiles_tex = sys.texture("tall_tiles.png", [2, 3]).unwrap();
22 let fat_tiles_tex = sys.texture("fat_tiles.png", [2, 3]).unwrap();
23 let leaves = sys.texture("leaves.png", [1, 1]).unwrap();
24
25 //Make a bunch of static vbos
26 let canvas = sys.canvas_mut();
27 let background = { canvas.rects().add([0.0, 640.0, 0.0, 480.0]).save(canvas) };
28 let rect_save = {
29 let mut k = canvas.rects();
30 k.add([300., 500., 300., 500.]);
31 k.save(canvas)
32 };
33 let square_save = {
34 let mut k = canvas.squares();
35 for x in (0..1000).step_by(100).map(|a| a as f32) {
36 for y in (0..1000).step_by(100).map(|a| a as f32) {
37 k.add([x, y]);
38 }
39 }
40 k.save(canvas)
41 };
42 let arrow_save = {
43 canvas
44 .arrows(5.0)
45 .add([40., 40.], [40., 200.])
46 .add([40., 40.], [200., 40.])
47 .save(canvas)
48 };
49 let line_save = {
50 canvas
51 .lines(3.0)
52 .add([400., 0.], [600., 400.])
53 .add([10., 300.], [300., 400.])
54 .save(canvas)
55 };
56 let sprite_save = {
57 let mut k = canvas.sprites();
58 for (i, x) in (032..200)
59 .step_by(32)
60 .enumerate()
61 .map(|(a, b)| (a as u8, b as f32))
62 {
63 for (j, y) in (032..200)
64 .step_by(32)
65 .enumerate()
66 .map(|(a, b)| (a as u8, b as f32))
67 {
68 k.add([x, y], food_tex.coord_to_index([i, j]), 0.0);
69 }
70 }
71 k.save(canvas)
72 };
73
74 //Draw 60 frames per second.
75 let mut timer = egaku2d::RefreshTimer::new(16);
76
77 let mut counter = 0;
78 let mut cursor = [0.0; 2];
79 events_loop.run(move |event, _, control_flow| match event {
80 Event::WindowEvent { event, .. } => match event {
81 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
82 Some(VirtualKeyCode::Escape) => {
83 *control_flow = ControlFlow::Exit;
84 }
85 _ => {}
86 },
87 WindowEvent::CursorMoved {
88 device_id: _,
89 position: p,
90 ..
91 } => {
92 cursor = [p.x as f32, p.y as f32];
93 }
94 WindowEvent::CloseRequested => {
95 *control_flow = ControlFlow::Exit;
96 }
97 WindowEvent::Resized(_dim) => {}
98 _ => {}
99 },
100
101 Event::MainEventsCleared => {
102 if timer.is_ready() {
103
104 let canvas = sys.canvas_mut();
105
106 //canvas.set_default_offset([-cursor[0],-cursor[1]]);
107
108
109 let cc = counter as f32 * 0.1;
110 let wobble = [cc.cos() * 10.0, cc.sin() * 10.0];
111
112 canvas.clear_color([0.2; 3]);
113
114 //draw static VBOs already on the gpu.
115 background
116 .uniforms(canvas)
117 .with_texture(&sky, 2.0, [0.0; 2])
118 .draw();
119
120 sprite_save
121 .uniforms(canvas, &food_tex, 32.0)
122 .with_color(COL4)
123 .with_offset([-wobble[0], -wobble[1]])
124 .draw();
125
126 arrow_save.uniforms(canvas).draw();
127 line_save.uniforms(canvas).with_color(COL2).draw();
128 square_save.uniforms(canvas, 10.0).with_color(COL3).draw();
129
130 let w=[wobble[0]+300.0,wobble[1]+300.0];
131 rect_save
132 .uniforms(canvas)
133 .with_texture(&fat_tiles_tex, 2.0, w)
134 .with_color(WHITE)
135 .with_offset(wobble)
136 .draw();
137
138 //Draw a bunch of dyanmic shapes.
139 let mut builder = canvas.circles();
140 for x in (0..1000).step_by(12).map(|a| a as f32) {
141 for y in (0..1000).step_by(12).map(|a| a as f32) {
142 let c = (counter as f32 + x + y) * 0.01;
143 let x = x + c.sin() * y * 0.1;
144 let y = y + c.cos() * x * 0.1;
145 builder.add([x, y]);
146 }
147 }
148 builder
149 .send_and_uniforms(canvas, 8.0)
150 .with_color(COL1)
151 .draw();
152
153 let mut builder = canvas.sprites();
154 for y in (100..500).step_by(80).map(|a| a as f32) {
155 for x in (100..500).step_by(80).map(|a| a as f32) {
156 let c = (counter as f32 + x + y) * 0.01;
157 let cc = ((counter as f32 + x + y) * 0.1) as u32;
158 let x = x + c.sin() * 20.0;
159 let y = y + c.cos() * 20.0;
160 builder.add([x, y], (cc % 64) as u16, c);
161 }
162 }
163 builder
164 .send_and_uniforms(canvas, &adventurer, 100.0)
165 .with_color(WHITE)
166 .draw();
167
168 let mut builder = canvas.sprites();
169 add_ascii(
170 [100., 400.],
171 20.0,
172 cc.cos() * 0.5 - 0.2,
173 "testing? TESTING!",
174 &mut builder,
175 );
176 builder.add([100., 100.], ascii_tex.coord_to_index([2, 2]), 1.0);
177 builder.send_and_uniforms(canvas, &ascii_tex, 20.0).draw();
178
179 let c = ((counter as f32 * 0.06).sin() * 100.0).abs();
180 canvas
181 .circles()
182 .add(cursor)
183 .send_and_uniforms(canvas, c)
184 .with_texture(&leaves, 1.0, [0.0; 2])
185 .draw();
186
187 //draw a moving line
188 let c = counter as f32 * 0.07;
189 canvas
190 .lines(10.)
191 .add([50., 500.], [500., 50. + c.sin() * 50.])
192 .send_and_uniforms(canvas)
193 .with_texture(&leaves, 4.0, [0.0; 2])
194 .draw();
195
196 //draw a rotating arrow
197 let c = counter as f32 * 0.04;
198 let center = [400., 400.];
199
200 let other = [center[0] + c.cos() * 80., center[1] + c.sin() * 80.];
201 canvas
202 .arrows(10.0)
203 .add(center, other)
204 .send_and_uniforms(canvas)
205 .with_color(COL4)
206 .draw();
207
208 canvas
209 .sprites()
210 .add([500., 200.], c as u16, c)
211 .send_and_uniforms(canvas, &fat_tiles_tex, 100.)
212 .draw();
213 canvas
214 .sprites()
215 .add([500., 50.], c as u16, c)
216 .send_and_uniforms(canvas, &tall_tiles_tex, 100.)
217 .draw();
218
219 //display what we drew
220 sys.swap_buffers();
221
222 counter += 1;
223 }
224 }
225 _ => {}
226 });
227}pub fn set_viewport_from_width(&mut self, width: f32)
pub fn set_viewport_min(&mut self, d: f32)
pub fn set_viewport_from_height(&mut self, height: f32)
pub fn get_dim(&self) -> [usize; 2]
Sourcepub fn texture(&mut self, file: &str, grid_dim: [u8; 2]) -> ImageResult<Texture>
pub fn texture(&mut self, file: &str, grid_dim: [u8; 2]) -> ImageResult<Texture>
Creates a new texture from the specified file. The fact that we need a mutable reference to this object Ensures that we make the texture in the same thread. The grid dimensions passed are the tile dimensions is the texture is a tile set.
Examples found in repository?
examples/demo.rs (line 17)
11fn main() {
12 let events_loop = glutin::event_loop::EventLoop::new();
13 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
14 //let mut sys=egaku2d::FullScreenSystem::new(&events_loop);
15
16 //Make a bunch of textures
17 let sky = sys.texture("day_sky.png", [1, 1]).unwrap();
18 let food_tex = sys.texture("food.png", [8, 8]).unwrap();
19 let adventurer = sys.texture("adventurer.png", [7, 11]).unwrap();
20 let ascii_tex = sys.texture("ascii.png", [16, 14]).unwrap();
21 let tall_tiles_tex = sys.texture("tall_tiles.png", [2, 3]).unwrap();
22 let fat_tiles_tex = sys.texture("fat_tiles.png", [2, 3]).unwrap();
23 let leaves = sys.texture("leaves.png", [1, 1]).unwrap();
24
25 //Make a bunch of static vbos
26 let canvas = sys.canvas_mut();
27 let background = { canvas.rects().add([0.0, 640.0, 0.0, 480.0]).save(canvas) };
28 let rect_save = {
29 let mut k = canvas.rects();
30 k.add([300., 500., 300., 500.]);
31 k.save(canvas)
32 };
33 let square_save = {
34 let mut k = canvas.squares();
35 for x in (0..1000).step_by(100).map(|a| a as f32) {
36 for y in (0..1000).step_by(100).map(|a| a as f32) {
37 k.add([x, y]);
38 }
39 }
40 k.save(canvas)
41 };
42 let arrow_save = {
43 canvas
44 .arrows(5.0)
45 .add([40., 40.], [40., 200.])
46 .add([40., 40.], [200., 40.])
47 .save(canvas)
48 };
49 let line_save = {
50 canvas
51 .lines(3.0)
52 .add([400., 0.], [600., 400.])
53 .add([10., 300.], [300., 400.])
54 .save(canvas)
55 };
56 let sprite_save = {
57 let mut k = canvas.sprites();
58 for (i, x) in (032..200)
59 .step_by(32)
60 .enumerate()
61 .map(|(a, b)| (a as u8, b as f32))
62 {
63 for (j, y) in (032..200)
64 .step_by(32)
65 .enumerate()
66 .map(|(a, b)| (a as u8, b as f32))
67 {
68 k.add([x, y], food_tex.coord_to_index([i, j]), 0.0);
69 }
70 }
71 k.save(canvas)
72 };
73
74 //Draw 60 frames per second.
75 let mut timer = egaku2d::RefreshTimer::new(16);
76
77 let mut counter = 0;
78 let mut cursor = [0.0; 2];
79 events_loop.run(move |event, _, control_flow| match event {
80 Event::WindowEvent { event, .. } => match event {
81 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
82 Some(VirtualKeyCode::Escape) => {
83 *control_flow = ControlFlow::Exit;
84 }
85 _ => {}
86 },
87 WindowEvent::CursorMoved {
88 device_id: _,
89 position: p,
90 ..
91 } => {
92 cursor = [p.x as f32, p.y as f32];
93 }
94 WindowEvent::CloseRequested => {
95 *control_flow = ControlFlow::Exit;
96 }
97 WindowEvent::Resized(_dim) => {}
98 _ => {}
99 },
100
101 Event::MainEventsCleared => {
102 if timer.is_ready() {
103
104 let canvas = sys.canvas_mut();
105
106 //canvas.set_default_offset([-cursor[0],-cursor[1]]);
107
108
109 let cc = counter as f32 * 0.1;
110 let wobble = [cc.cos() * 10.0, cc.sin() * 10.0];
111
112 canvas.clear_color([0.2; 3]);
113
114 //draw static VBOs already on the gpu.
115 background
116 .uniforms(canvas)
117 .with_texture(&sky, 2.0, [0.0; 2])
118 .draw();
119
120 sprite_save
121 .uniforms(canvas, &food_tex, 32.0)
122 .with_color(COL4)
123 .with_offset([-wobble[0], -wobble[1]])
124 .draw();
125
126 arrow_save.uniforms(canvas).draw();
127 line_save.uniforms(canvas).with_color(COL2).draw();
128 square_save.uniforms(canvas, 10.0).with_color(COL3).draw();
129
130 let w=[wobble[0]+300.0,wobble[1]+300.0];
131 rect_save
132 .uniforms(canvas)
133 .with_texture(&fat_tiles_tex, 2.0, w)
134 .with_color(WHITE)
135 .with_offset(wobble)
136 .draw();
137
138 //Draw a bunch of dyanmic shapes.
139 let mut builder = canvas.circles();
140 for x in (0..1000).step_by(12).map(|a| a as f32) {
141 for y in (0..1000).step_by(12).map(|a| a as f32) {
142 let c = (counter as f32 + x + y) * 0.01;
143 let x = x + c.sin() * y * 0.1;
144 let y = y + c.cos() * x * 0.1;
145 builder.add([x, y]);
146 }
147 }
148 builder
149 .send_and_uniforms(canvas, 8.0)
150 .with_color(COL1)
151 .draw();
152
153 let mut builder = canvas.sprites();
154 for y in (100..500).step_by(80).map(|a| a as f32) {
155 for x in (100..500).step_by(80).map(|a| a as f32) {
156 let c = (counter as f32 + x + y) * 0.01;
157 let cc = ((counter as f32 + x + y) * 0.1) as u32;
158 let x = x + c.sin() * 20.0;
159 let y = y + c.cos() * 20.0;
160 builder.add([x, y], (cc % 64) as u16, c);
161 }
162 }
163 builder
164 .send_and_uniforms(canvas, &adventurer, 100.0)
165 .with_color(WHITE)
166 .draw();
167
168 let mut builder = canvas.sprites();
169 add_ascii(
170 [100., 400.],
171 20.0,
172 cc.cos() * 0.5 - 0.2,
173 "testing? TESTING!",
174 &mut builder,
175 );
176 builder.add([100., 100.], ascii_tex.coord_to_index([2, 2]), 1.0);
177 builder.send_and_uniforms(canvas, &ascii_tex, 20.0).draw();
178
179 let c = ((counter as f32 * 0.06).sin() * 100.0).abs();
180 canvas
181 .circles()
182 .add(cursor)
183 .send_and_uniforms(canvas, c)
184 .with_texture(&leaves, 1.0, [0.0; 2])
185 .draw();
186
187 //draw a moving line
188 let c = counter as f32 * 0.07;
189 canvas
190 .lines(10.)
191 .add([50., 500.], [500., 50. + c.sin() * 50.])
192 .send_and_uniforms(canvas)
193 .with_texture(&leaves, 4.0, [0.0; 2])
194 .draw();
195
196 //draw a rotating arrow
197 let c = counter as f32 * 0.04;
198 let center = [400., 400.];
199
200 let other = [center[0] + c.cos() * 80., center[1] + c.sin() * 80.];
201 canvas
202 .arrows(10.0)
203 .add(center, other)
204 .send_and_uniforms(canvas)
205 .with_color(COL4)
206 .draw();
207
208 canvas
209 .sprites()
210 .add([500., 200.], c as u16, c)
211 .send_and_uniforms(canvas, &fat_tiles_tex, 100.)
212 .draw();
213 canvas
214 .sprites()
215 .add([500., 50.], c as u16, c)
216 .send_and_uniforms(canvas, &tall_tiles_tex, 100.)
217 .draw();
218
219 //display what we drew
220 sys.swap_buffers();
221
222 counter += 1;
223 }
224 }
225 _ => {}
226 });
227}pub fn canvas(&self) -> &SimpleCanvas
Sourcepub fn canvas_mut(&mut self) -> &mut SimpleCanvas
pub fn canvas_mut(&mut self) -> &mut SimpleCanvas
Examples found in repository?
examples/simple.rs (line 38)
6fn main() {
7 let events_loop = glutin::event_loop::EventLoop::new();
8 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
9
10 //Draw 60 frames per second.
11 let mut timer = egaku2d::RefreshTimer::new(16);
12
13 let mut cursor = [0.0; 2];
14 events_loop.run(move |event, _, control_flow| match event {
15 Event::WindowEvent { event, .. } => match event {
16 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
17 Some(VirtualKeyCode::Escape) => {
18 *control_flow = ControlFlow::Exit;
19 }
20 _ => {}
21 },
22 WindowEvent::CursorMoved {
23 device_id: _,
24 position: p,
25 ..
26 } => {
27 cursor = [p.x as f32, p.y as f32];
28 }
29 WindowEvent::CloseRequested => {
30 *control_flow = ControlFlow::Exit;
31 }
32 WindowEvent::Resized(_dim) => {}
33 _ => {}
34 },
35
36 Event::MainEventsCleared => {
37 if timer.is_ready() {
38 let canvas = sys.canvas_mut();
39
40 canvas.clear_color([0.2; 3]);
41
42 let mut circles = canvas.circles();
43
44 for x in (20..400).step_by(20) {
45 for y in (20..400).step_by(20) {
46 circles.add([
47 cursor[0] + (x as f32) * (cursor[0] * 0.01),
48 cursor[1] + y as f32,
49 ]);
50 }
51 }
52
53 circles
54 .send_and_uniforms(canvas, 10.0)
55 .with_color([1.0, 1.0, 1.0, 1.0])
56 .draw();
57
58 //display what we drew
59 sys.swap_buffers();
60 }
61 }
62 _ => {}
63 });
64}More examples
examples/demo.rs (line 26)
11fn main() {
12 let events_loop = glutin::event_loop::EventLoop::new();
13 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
14 //let mut sys=egaku2d::FullScreenSystem::new(&events_loop);
15
16 //Make a bunch of textures
17 let sky = sys.texture("day_sky.png", [1, 1]).unwrap();
18 let food_tex = sys.texture("food.png", [8, 8]).unwrap();
19 let adventurer = sys.texture("adventurer.png", [7, 11]).unwrap();
20 let ascii_tex = sys.texture("ascii.png", [16, 14]).unwrap();
21 let tall_tiles_tex = sys.texture("tall_tiles.png", [2, 3]).unwrap();
22 let fat_tiles_tex = sys.texture("fat_tiles.png", [2, 3]).unwrap();
23 let leaves = sys.texture("leaves.png", [1, 1]).unwrap();
24
25 //Make a bunch of static vbos
26 let canvas = sys.canvas_mut();
27 let background = { canvas.rects().add([0.0, 640.0, 0.0, 480.0]).save(canvas) };
28 let rect_save = {
29 let mut k = canvas.rects();
30 k.add([300., 500., 300., 500.]);
31 k.save(canvas)
32 };
33 let square_save = {
34 let mut k = canvas.squares();
35 for x in (0..1000).step_by(100).map(|a| a as f32) {
36 for y in (0..1000).step_by(100).map(|a| a as f32) {
37 k.add([x, y]);
38 }
39 }
40 k.save(canvas)
41 };
42 let arrow_save = {
43 canvas
44 .arrows(5.0)
45 .add([40., 40.], [40., 200.])
46 .add([40., 40.], [200., 40.])
47 .save(canvas)
48 };
49 let line_save = {
50 canvas
51 .lines(3.0)
52 .add([400., 0.], [600., 400.])
53 .add([10., 300.], [300., 400.])
54 .save(canvas)
55 };
56 let sprite_save = {
57 let mut k = canvas.sprites();
58 for (i, x) in (032..200)
59 .step_by(32)
60 .enumerate()
61 .map(|(a, b)| (a as u8, b as f32))
62 {
63 for (j, y) in (032..200)
64 .step_by(32)
65 .enumerate()
66 .map(|(a, b)| (a as u8, b as f32))
67 {
68 k.add([x, y], food_tex.coord_to_index([i, j]), 0.0);
69 }
70 }
71 k.save(canvas)
72 };
73
74 //Draw 60 frames per second.
75 let mut timer = egaku2d::RefreshTimer::new(16);
76
77 let mut counter = 0;
78 let mut cursor = [0.0; 2];
79 events_loop.run(move |event, _, control_flow| match event {
80 Event::WindowEvent { event, .. } => match event {
81 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
82 Some(VirtualKeyCode::Escape) => {
83 *control_flow = ControlFlow::Exit;
84 }
85 _ => {}
86 },
87 WindowEvent::CursorMoved {
88 device_id: _,
89 position: p,
90 ..
91 } => {
92 cursor = [p.x as f32, p.y as f32];
93 }
94 WindowEvent::CloseRequested => {
95 *control_flow = ControlFlow::Exit;
96 }
97 WindowEvent::Resized(_dim) => {}
98 _ => {}
99 },
100
101 Event::MainEventsCleared => {
102 if timer.is_ready() {
103
104 let canvas = sys.canvas_mut();
105
106 //canvas.set_default_offset([-cursor[0],-cursor[1]]);
107
108
109 let cc = counter as f32 * 0.1;
110 let wobble = [cc.cos() * 10.0, cc.sin() * 10.0];
111
112 canvas.clear_color([0.2; 3]);
113
114 //draw static VBOs already on the gpu.
115 background
116 .uniforms(canvas)
117 .with_texture(&sky, 2.0, [0.0; 2])
118 .draw();
119
120 sprite_save
121 .uniforms(canvas, &food_tex, 32.0)
122 .with_color(COL4)
123 .with_offset([-wobble[0], -wobble[1]])
124 .draw();
125
126 arrow_save.uniforms(canvas).draw();
127 line_save.uniforms(canvas).with_color(COL2).draw();
128 square_save.uniforms(canvas, 10.0).with_color(COL3).draw();
129
130 let w=[wobble[0]+300.0,wobble[1]+300.0];
131 rect_save
132 .uniforms(canvas)
133 .with_texture(&fat_tiles_tex, 2.0, w)
134 .with_color(WHITE)
135 .with_offset(wobble)
136 .draw();
137
138 //Draw a bunch of dyanmic shapes.
139 let mut builder = canvas.circles();
140 for x in (0..1000).step_by(12).map(|a| a as f32) {
141 for y in (0..1000).step_by(12).map(|a| a as f32) {
142 let c = (counter as f32 + x + y) * 0.01;
143 let x = x + c.sin() * y * 0.1;
144 let y = y + c.cos() * x * 0.1;
145 builder.add([x, y]);
146 }
147 }
148 builder
149 .send_and_uniforms(canvas, 8.0)
150 .with_color(COL1)
151 .draw();
152
153 let mut builder = canvas.sprites();
154 for y in (100..500).step_by(80).map(|a| a as f32) {
155 for x in (100..500).step_by(80).map(|a| a as f32) {
156 let c = (counter as f32 + x + y) * 0.01;
157 let cc = ((counter as f32 + x + y) * 0.1) as u32;
158 let x = x + c.sin() * 20.0;
159 let y = y + c.cos() * 20.0;
160 builder.add([x, y], (cc % 64) as u16, c);
161 }
162 }
163 builder
164 .send_and_uniforms(canvas, &adventurer, 100.0)
165 .with_color(WHITE)
166 .draw();
167
168 let mut builder = canvas.sprites();
169 add_ascii(
170 [100., 400.],
171 20.0,
172 cc.cos() * 0.5 - 0.2,
173 "testing? TESTING!",
174 &mut builder,
175 );
176 builder.add([100., 100.], ascii_tex.coord_to_index([2, 2]), 1.0);
177 builder.send_and_uniforms(canvas, &ascii_tex, 20.0).draw();
178
179 let c = ((counter as f32 * 0.06).sin() * 100.0).abs();
180 canvas
181 .circles()
182 .add(cursor)
183 .send_and_uniforms(canvas, c)
184 .with_texture(&leaves, 1.0, [0.0; 2])
185 .draw();
186
187 //draw a moving line
188 let c = counter as f32 * 0.07;
189 canvas
190 .lines(10.)
191 .add([50., 500.], [500., 50. + c.sin() * 50.])
192 .send_and_uniforms(canvas)
193 .with_texture(&leaves, 4.0, [0.0; 2])
194 .draw();
195
196 //draw a rotating arrow
197 let c = counter as f32 * 0.04;
198 let center = [400., 400.];
199
200 let other = [center[0] + c.cos() * 80., center[1] + c.sin() * 80.];
201 canvas
202 .arrows(10.0)
203 .add(center, other)
204 .send_and_uniforms(canvas)
205 .with_color(COL4)
206 .draw();
207
208 canvas
209 .sprites()
210 .add([500., 200.], c as u16, c)
211 .send_and_uniforms(canvas, &fat_tiles_tex, 100.)
212 .draw();
213 canvas
214 .sprites()
215 .add([500., 50.], c as u16, c)
216 .send_and_uniforms(canvas, &tall_tiles_tex, 100.)
217 .draw();
218
219 //display what we drew
220 sys.swap_buffers();
221
222 counter += 1;
223 }
224 }
225 _ => {}
226 });
227}Sourcepub fn swap_buffers(&mut self)
pub fn swap_buffers(&mut self)
Examples found in repository?
examples/simple.rs (line 59)
6fn main() {
7 let events_loop = glutin::event_loop::EventLoop::new();
8 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
9
10 //Draw 60 frames per second.
11 let mut timer = egaku2d::RefreshTimer::new(16);
12
13 let mut cursor = [0.0; 2];
14 events_loop.run(move |event, _, control_flow| match event {
15 Event::WindowEvent { event, .. } => match event {
16 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
17 Some(VirtualKeyCode::Escape) => {
18 *control_flow = ControlFlow::Exit;
19 }
20 _ => {}
21 },
22 WindowEvent::CursorMoved {
23 device_id: _,
24 position: p,
25 ..
26 } => {
27 cursor = [p.x as f32, p.y as f32];
28 }
29 WindowEvent::CloseRequested => {
30 *control_flow = ControlFlow::Exit;
31 }
32 WindowEvent::Resized(_dim) => {}
33 _ => {}
34 },
35
36 Event::MainEventsCleared => {
37 if timer.is_ready() {
38 let canvas = sys.canvas_mut();
39
40 canvas.clear_color([0.2; 3]);
41
42 let mut circles = canvas.circles();
43
44 for x in (20..400).step_by(20) {
45 for y in (20..400).step_by(20) {
46 circles.add([
47 cursor[0] + (x as f32) * (cursor[0] * 0.01),
48 cursor[1] + y as f32,
49 ]);
50 }
51 }
52
53 circles
54 .send_and_uniforms(canvas, 10.0)
55 .with_color([1.0, 1.0, 1.0, 1.0])
56 .draw();
57
58 //display what we drew
59 sys.swap_buffers();
60 }
61 }
62 _ => {}
63 });
64}More examples
examples/demo.rs (line 220)
11fn main() {
12 let events_loop = glutin::event_loop::EventLoop::new();
13 let mut sys = egaku2d::WindowedSystem::new([640, 480], &events_loop, "shapes example");
14 //let mut sys=egaku2d::FullScreenSystem::new(&events_loop);
15
16 //Make a bunch of textures
17 let sky = sys.texture("day_sky.png", [1, 1]).unwrap();
18 let food_tex = sys.texture("food.png", [8, 8]).unwrap();
19 let adventurer = sys.texture("adventurer.png", [7, 11]).unwrap();
20 let ascii_tex = sys.texture("ascii.png", [16, 14]).unwrap();
21 let tall_tiles_tex = sys.texture("tall_tiles.png", [2, 3]).unwrap();
22 let fat_tiles_tex = sys.texture("fat_tiles.png", [2, 3]).unwrap();
23 let leaves = sys.texture("leaves.png", [1, 1]).unwrap();
24
25 //Make a bunch of static vbos
26 let canvas = sys.canvas_mut();
27 let background = { canvas.rects().add([0.0, 640.0, 0.0, 480.0]).save(canvas) };
28 let rect_save = {
29 let mut k = canvas.rects();
30 k.add([300., 500., 300., 500.]);
31 k.save(canvas)
32 };
33 let square_save = {
34 let mut k = canvas.squares();
35 for x in (0..1000).step_by(100).map(|a| a as f32) {
36 for y in (0..1000).step_by(100).map(|a| a as f32) {
37 k.add([x, y]);
38 }
39 }
40 k.save(canvas)
41 };
42 let arrow_save = {
43 canvas
44 .arrows(5.0)
45 .add([40., 40.], [40., 200.])
46 .add([40., 40.], [200., 40.])
47 .save(canvas)
48 };
49 let line_save = {
50 canvas
51 .lines(3.0)
52 .add([400., 0.], [600., 400.])
53 .add([10., 300.], [300., 400.])
54 .save(canvas)
55 };
56 let sprite_save = {
57 let mut k = canvas.sprites();
58 for (i, x) in (032..200)
59 .step_by(32)
60 .enumerate()
61 .map(|(a, b)| (a as u8, b as f32))
62 {
63 for (j, y) in (032..200)
64 .step_by(32)
65 .enumerate()
66 .map(|(a, b)| (a as u8, b as f32))
67 {
68 k.add([x, y], food_tex.coord_to_index([i, j]), 0.0);
69 }
70 }
71 k.save(canvas)
72 };
73
74 //Draw 60 frames per second.
75 let mut timer = egaku2d::RefreshTimer::new(16);
76
77 let mut counter = 0;
78 let mut cursor = [0.0; 2];
79 events_loop.run(move |event, _, control_flow| match event {
80 Event::WindowEvent { event, .. } => match event {
81 WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
82 Some(VirtualKeyCode::Escape) => {
83 *control_flow = ControlFlow::Exit;
84 }
85 _ => {}
86 },
87 WindowEvent::CursorMoved {
88 device_id: _,
89 position: p,
90 ..
91 } => {
92 cursor = [p.x as f32, p.y as f32];
93 }
94 WindowEvent::CloseRequested => {
95 *control_flow = ControlFlow::Exit;
96 }
97 WindowEvent::Resized(_dim) => {}
98 _ => {}
99 },
100
101 Event::MainEventsCleared => {
102 if timer.is_ready() {
103
104 let canvas = sys.canvas_mut();
105
106 //canvas.set_default_offset([-cursor[0],-cursor[1]]);
107
108
109 let cc = counter as f32 * 0.1;
110 let wobble = [cc.cos() * 10.0, cc.sin() * 10.0];
111
112 canvas.clear_color([0.2; 3]);
113
114 //draw static VBOs already on the gpu.
115 background
116 .uniforms(canvas)
117 .with_texture(&sky, 2.0, [0.0; 2])
118 .draw();
119
120 sprite_save
121 .uniforms(canvas, &food_tex, 32.0)
122 .with_color(COL4)
123 .with_offset([-wobble[0], -wobble[1]])
124 .draw();
125
126 arrow_save.uniforms(canvas).draw();
127 line_save.uniforms(canvas).with_color(COL2).draw();
128 square_save.uniforms(canvas, 10.0).with_color(COL3).draw();
129
130 let w=[wobble[0]+300.0,wobble[1]+300.0];
131 rect_save
132 .uniforms(canvas)
133 .with_texture(&fat_tiles_tex, 2.0, w)
134 .with_color(WHITE)
135 .with_offset(wobble)
136 .draw();
137
138 //Draw a bunch of dyanmic shapes.
139 let mut builder = canvas.circles();
140 for x in (0..1000).step_by(12).map(|a| a as f32) {
141 for y in (0..1000).step_by(12).map(|a| a as f32) {
142 let c = (counter as f32 + x + y) * 0.01;
143 let x = x + c.sin() * y * 0.1;
144 let y = y + c.cos() * x * 0.1;
145 builder.add([x, y]);
146 }
147 }
148 builder
149 .send_and_uniforms(canvas, 8.0)
150 .with_color(COL1)
151 .draw();
152
153 let mut builder = canvas.sprites();
154 for y in (100..500).step_by(80).map(|a| a as f32) {
155 for x in (100..500).step_by(80).map(|a| a as f32) {
156 let c = (counter as f32 + x + y) * 0.01;
157 let cc = ((counter as f32 + x + y) * 0.1) as u32;
158 let x = x + c.sin() * 20.0;
159 let y = y + c.cos() * 20.0;
160 builder.add([x, y], (cc % 64) as u16, c);
161 }
162 }
163 builder
164 .send_and_uniforms(canvas, &adventurer, 100.0)
165 .with_color(WHITE)
166 .draw();
167
168 let mut builder = canvas.sprites();
169 add_ascii(
170 [100., 400.],
171 20.0,
172 cc.cos() * 0.5 - 0.2,
173 "testing? TESTING!",
174 &mut builder,
175 );
176 builder.add([100., 100.], ascii_tex.coord_to_index([2, 2]), 1.0);
177 builder.send_and_uniforms(canvas, &ascii_tex, 20.0).draw();
178
179 let c = ((counter as f32 * 0.06).sin() * 100.0).abs();
180 canvas
181 .circles()
182 .add(cursor)
183 .send_and_uniforms(canvas, c)
184 .with_texture(&leaves, 1.0, [0.0; 2])
185 .draw();
186
187 //draw a moving line
188 let c = counter as f32 * 0.07;
189 canvas
190 .lines(10.)
191 .add([50., 500.], [500., 50. + c.sin() * 50.])
192 .send_and_uniforms(canvas)
193 .with_texture(&leaves, 4.0, [0.0; 2])
194 .draw();
195
196 //draw a rotating arrow
197 let c = counter as f32 * 0.04;
198 let center = [400., 400.];
199
200 let other = [center[0] + c.cos() * 80., center[1] + c.sin() * 80.];
201 canvas
202 .arrows(10.0)
203 .add(center, other)
204 .send_and_uniforms(canvas)
205 .with_color(COL4)
206 .draw();
207
208 canvas
209 .sprites()
210 .add([500., 200.], c as u16, c)
211 .send_and_uniforms(canvas, &fat_tiles_tex, 100.)
212 .draw();
213 canvas
214 .sprites()
215 .add([500., 50.], c as u16, c)
216 .send_and_uniforms(canvas, &tall_tiles_tex, 100.)
217 .draw();
218
219 //display what we drew
220 sys.swap_buffers();
221
222 counter += 1;
223 }
224 }
225 _ => {}
226 });
227}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WindowedSystem
impl !RefUnwindSafe for WindowedSystem
impl !Send for WindowedSystem
impl !Sync for WindowedSystem
impl Unpin for WindowedSystem
impl UnsafeUnpin for WindowedSystem
impl !UnwindSafe for WindowedSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more