MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / main

Function main

draw/examples/render_window.rs:11–45  ·  view source on GitHub ↗

Simple example that displays a render window and renders a triangle

()

Source from the content-addressed store, hash-verified

9/// Simple example that displays a render window and renders a triangle
10///
11pub fn main() {
12 // 'with_2d_graphics' is used to support operating systems that can't run event loops anywhere other than the main thread
13 with_2d_graphics(|| {
14 // Create a render window and loop until it stops sending events
15 executor::block_on(async {
16 // Create a window
17 let (mut renderer, mut events) = create_render_window("Direct render action window");
18
19 // Render a triangle to it
20 let black = [0, 0, 0, 255];
21 renderer.publish(vec![
22 RenderAction::Clear(Rgba8([128, 128, 128, 255])),
23 RenderAction::SetTransform(Matrix::identity()),
24 RenderAction::UseShader(ShaderType::Simple { erase_texture: None, clip_texture: None }),
25 RenderAction::CreateVertex2DBuffer(VertexBufferId(0), vec![
26 Vertex2D { pos: [-1.0, -1.0], tex_coord: [0.0, 0.0], color: black },
27 Vertex2D { pos: [1.0, 1.0], tex_coord: [0.0, 0.0], color: black },
28 Vertex2D { pos: [1.0, -1.0], tex_coord: [0.0, 0.0], color: black },
29 ]),
30 RenderAction::DrawTriangles(VertexBufferId(0), 0..3),
31
32 RenderAction::ShowFrameBuffer
33 ]).await;
34
35 // Wait until it stops producing events
36 while let Some(evt) = events.next().await {
37 // Stop reading events when the window is closed (this will close our streams, so the window will disappear)
38 match evt {
39 DrawEvent::Closed => { break; }
40 _ => { }
41 }
42 }
43 });
44 });
45}

Callers

nothing calls this directly

Calls 2

with_2d_graphicsFunction · 0.85
create_render_windowFunction · 0.85

Tested by

no test coverage detected