pub struct DrawingContext { /* private fields */ }Expand description
DrawingContext is an intermediate mode for drawing 2D primitives.
It provides methods to draw rectangles, lines, triangles, circles, and images with various options for colors and textures.
Implementations§
Source§impl DrawingContext
impl DrawingContext
Sourcepub fn load_font(
&mut self,
font_path: &str,
range: Option<&[(u32, u32)]>,
size: f32,
)
pub fn load_font( &mut self, font_path: &str, range: Option<&[(u32, u32)]>, size: f32, )
Load a font from the specified path with an optional range of codepoints and size.
Sourcepub fn set_font(&mut self, font: &Font)
pub fn set_font(&mut self, font: &Font)
Set the current font to be used for drawing text.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Font Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut font_manager = est_render::font::new();
18
19 let font = font_manager
20 .load_font("Arial", None, 20.0)
21 .expect("Failed to load font");
22
23 // Generate baked text texture
24 let texture = font
25 .create_baked_text(&mut gpu, "Hello, World!\nThis is a clear color example.", None)
26 .expect("Failed to create baked text");
27
28 while runner.pump_events(None) {
29 for event in runner.get_events() {
30 match event {
31 Event::WindowClosed { .. } => {
32 return;
33 }
34 _ => {}
35 }
36 }
37
38 if let Ok(mut cmd) = gpu.begin_command() {
39 if let Ok(mut gp) = cmd.begin_renderpass() {
40 gp.set_clear_color(Color::BLUE);
41
42 // The best texture blend for font rendering, others may has artifacts like black borders
43 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 let size: Vector2 = texture.size().into();
47
48 // Baked text rendering
49 drawing.set_texture(Some(&texture));
50 drawing.draw_rect_image(Vector2::new(0.0, 0.0), size, Color::WHITE);
51
52 // Online text rendering
53 drawing.set_font(&font);
54 drawing.draw_text(
55 "Hello, World!\nThis is a clear color example.",
56 Vector2::new(size.x, 0.0),
57 Color::WHITE,
58 );
59 }
60 }
61 }
62 }
63}Sourcepub fn draw_text(&mut self, text: &str, pos: Vector2, color: Color)
pub fn draw_text(&mut self, text: &str, pos: Vector2, color: Color)
Draw text with a specified position, color, and font.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Drawing Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut rotation = 0.0f32;
18 while runner.pump_events(None) {
19 for event in runner.get_events() {
20 match event {
21 Event::WindowClosed { .. } => {
22 return;
23 }
24 _ => {}
25 }
26 }
27
28 rotation += runner.get_frame_time() as f32 * 60.0f32; // Rotate at 60 degrees per second
29 if rotation >= 360.0 {
30 rotation -= 360.0; // Reset rotation after a full circle
31 }
32
33 if let Ok(mut cmd) = gpu.begin_command() {
34 if let Ok(mut gp) = cmd.begin_renderpass() {
35 gp.set_clear_color(Color::BLUE); // Set the clear color to blue
36
37 if let Some(mut drawing) = gp.begin_drawing() {
38 drawing.set_rotation(rotation); // Set rotation to 45 degrees
39 gp.set_blend(0, Some(&BlendState::ALPHA_BLEND));
40 drawing.draw_rect_filled(
41 Vector2::new(100.0, 100.0),
42 Vector2::new(200.0, 200.0),
43 Color::RED,
44 );
45
46 drawing.draw_circle_filled(Vector2::new(400.0, 300.0), 50.0, 25, Color::GREEN);
47
48 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
49
50 drawing.draw_text(
51 "Hello, World!",
52 Vector2::new(300.0, 500.0),
53 Color::WHITE,
54 );
55 }
56 }
57 }
58 }
59}More examples
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Font Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut font_manager = est_render::font::new();
18
19 let font = font_manager
20 .load_font("Arial", None, 20.0)
21 .expect("Failed to load font");
22
23 // Generate baked text texture
24 let texture = font
25 .create_baked_text(&mut gpu, "Hello, World!\nThis is a clear color example.", None)
26 .expect("Failed to create baked text");
27
28 while runner.pump_events(None) {
29 for event in runner.get_events() {
30 match event {
31 Event::WindowClosed { .. } => {
32 return;
33 }
34 _ => {}
35 }
36 }
37
38 if let Ok(mut cmd) = gpu.begin_command() {
39 if let Ok(mut gp) = cmd.begin_renderpass() {
40 gp.set_clear_color(Color::BLUE);
41
42 // The best texture blend for font rendering, others may has artifacts like black borders
43 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 let size: Vector2 = texture.size().into();
47
48 // Baked text rendering
49 drawing.set_texture(Some(&texture));
50 drawing.draw_rect_image(Vector2::new(0.0, 0.0), size, Color::WHITE);
51
52 // Online text rendering
53 drawing.set_font(&font);
54 drawing.draw_text(
55 "Hello, World!\nThis is a clear color example.",
56 Vector2::new(size.x, 0.0),
57 Color::WHITE,
58 );
59 }
60 }
61 }
62 }
63}Sourcepub fn draw_rect(
&mut self,
pos: Vector2,
size: Vector2,
thickness: f32,
color: Color,
)
pub fn draw_rect( &mut self, pos: Vector2, size: Vector2, thickness: f32, color: Color, )
Draw hollow rectangle with a specified position, size, thickness, and color.
Sourcepub fn draw_line(
&mut self,
a: Vector2,
b: Vector2,
thickness: f32,
color: Color,
)
pub fn draw_line( &mut self, a: Vector2, b: Vector2, thickness: f32, color: Color, )
Draw line between two points with a specified thickness and color.
Sourcepub fn draw_rect_filled(&mut self, pos: Vector2, size: Vector2, color: Color)
pub fn draw_rect_filled(&mut self, pos: Vector2, size: Vector2, color: Color)
Draw rectangle filled with a specified position, size, and color.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Drawing Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut rotation = 0.0f32;
18 while runner.pump_events(None) {
19 for event in runner.get_events() {
20 match event {
21 Event::WindowClosed { .. } => {
22 return;
23 }
24 _ => {}
25 }
26 }
27
28 rotation += runner.get_frame_time() as f32 * 60.0f32; // Rotate at 60 degrees per second
29 if rotation >= 360.0 {
30 rotation -= 360.0; // Reset rotation after a full circle
31 }
32
33 if let Ok(mut cmd) = gpu.begin_command() {
34 if let Ok(mut gp) = cmd.begin_renderpass() {
35 gp.set_clear_color(Color::BLUE); // Set the clear color to blue
36
37 if let Some(mut drawing) = gp.begin_drawing() {
38 drawing.set_rotation(rotation); // Set rotation to 45 degrees
39 gp.set_blend(0, Some(&BlendState::ALPHA_BLEND));
40 drawing.draw_rect_filled(
41 Vector2::new(100.0, 100.0),
42 Vector2::new(200.0, 200.0),
43 Color::RED,
44 );
45
46 drawing.draw_circle_filled(Vector2::new(400.0, 300.0), 50.0, 25, Color::GREEN);
47
48 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
49
50 drawing.draw_text(
51 "Hello, World!",
52 Vector2::new(300.0, 500.0),
53 Color::WHITE,
54 );
55 }
56 }
57 }
58 }
59}Sourcepub fn draw_rect_filled_colors(
&mut self,
pos: Vector2,
size: Vector2,
color_tl: Color,
color_tr: Color,
color_br: Color,
color_bl: Color,
)
pub fn draw_rect_filled_colors( &mut self, pos: Vector2, size: Vector2, color_tl: Color, color_tr: Color, color_br: Color, color_bl: Color, )
Draw rectangle filled with specified colors for each corner.
Sourcepub fn draw_triangle(
&mut self,
a: Vector2,
b: Vector2,
c: Vector2,
thickness: f32,
color: Color,
)
pub fn draw_triangle( &mut self, a: Vector2, b: Vector2, c: Vector2, thickness: f32, color: Color, )
Draw triangle with specified vertices, thickness, and color.
Sourcepub fn draw_triangle_filled(
&mut self,
a: Vector2,
b: Vector2,
c: Vector2,
color: Color,
)
pub fn draw_triangle_filled( &mut self, a: Vector2, b: Vector2, c: Vector2, color: Color, )
Draw triangle filled with specified vertices and color.
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7 let mut window = runner
8 .create_window("Engine Example", Point2::new(800, 600))
9 .build()
10 .expect("Failed to create window");
11
12 let mut gpu = est_render::gpu::new(Some(&mut window))
13 .build()
14 .expect("Failed to create GPU");
15
16 let mut msaa_texture = Some(
17 gpu.create_texture()
18 .set_render_target(Point2::new(800, 600), None)
19 .set_usage(TextureUsage::Sampler)
20 .set_sample_count(SampleCount::SampleCount4)
21 .build()
22 .expect("Failed to create MSAA texture"),
23 );
24
25 let mut msaa_count = SampleCount::SampleCount4;
26 let mut window_size = Point2::new(800, 600);
27
28 while runner.pump_events(None) {
29 for event in runner.get_events() {
30 match event {
31 Event::WindowClosed { .. } => {
32 return;
33 }
34 Event::KeyboardInput { key, pressed, .. } => {
35 if !*pressed {
36 continue;
37 }
38
39 let mut need_recreate = false;
40 if *key == "1" {
41 msaa_count = SampleCount::SampleCount1;
42 need_recreate = true;
43 }
44
45 if *key == "2" {
46 msaa_count = SampleCount::SampleCount2;
47 need_recreate = true;
48 }
49
50 if *key == "3" {
51 msaa_count = SampleCount::SampleCount4;
52 need_recreate = true;
53 }
54
55 if *key == "4" {
56 msaa_count = SampleCount::SampleCount8;
57 need_recreate = true;
58 }
59
60 if need_recreate {
61 if msaa_count == SampleCount::SampleCount1 {
62 msaa_texture = None;
63 } else {
64 msaa_texture = Some(
65 gpu.create_texture()
66 .set_render_target(
67 Point2::new(window_size.x, window_size.y),
68 None,
69 )
70 .set_usage(TextureUsage::Sampler)
71 .set_sample_count(msaa_count)
72 .build()
73 .expect("Failed to recreate MSAA texture"),
74 );
75 }
76 }
77 }
78 Event::WindowResized { size, .. } => {
79 if size.x <= 0 || size.y <= 0 {
80 eprintln!("Invalid window size: {:?}", size);
81 continue;
82 }
83
84 window_size = *size;
85
86 // Resize the MSAA texture to match the new window size
87 msaa_texture = Some(
88 gpu.create_texture()
89 .set_render_target(Point2::new(size.x, size.y), None)
90 .set_usage(TextureUsage::Sampler)
91 .set_sample_count(msaa_count)
92 .build()
93 .expect("Failed to resize MSAA texture"),
94 );
95 }
96 _ => {}
97 }
98 }
99
100 if let Ok(mut cmd) = gpu.begin_command() {
101 if let Ok(mut rp) = cmd.begin_renderpass() {
102 rp.set_clear_color(Color::BLACK);
103 if let Some(texture) = msaa_texture.as_ref() {
104 rp.push_msaa_texture(texture);
105 }
106
107 if let Some(mut drawing) = rp.begin_drawing() {
108 let pos1 = Vector2::new(0.0, 0.0);
109 let pos2 = Vector2::new(800.0, 0.0);
110 let pos3 = Vector2::new(400.0, 600.0);
111
112 // Draw a full triangle covering the window
113 drawing.draw_triangle_filled(pos1, pos2, pos3, Color::BLUE);
114 }
115 }
116 }
117 }
118}pub fn draw_triangle_filled_colors( &mut self, a: Vector2, b: Vector2, c: Vector2, color_a: Color, color_b: Color, color_c: Color, )
Sourcepub fn draw_circle(
&mut self,
center: Vector2,
radius: f32,
segments: u32,
thickness: f32,
color: Color,
)
pub fn draw_circle( &mut self, center: Vector2, radius: f32, segments: u32, thickness: f32, color: Color, )
Draw circle with a specified center, radius, number of segments, thickness, and color.
Sourcepub fn draw_circle_filled(
&mut self,
center: Vector2,
radius: f32,
segments: u32,
color: Color,
)
pub fn draw_circle_filled( &mut self, center: Vector2, radius: f32, segments: u32, color: Color, )
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Drawing Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut rotation = 0.0f32;
18 while runner.pump_events(None) {
19 for event in runner.get_events() {
20 match event {
21 Event::WindowClosed { .. } => {
22 return;
23 }
24 _ => {}
25 }
26 }
27
28 rotation += runner.get_frame_time() as f32 * 60.0f32; // Rotate at 60 degrees per second
29 if rotation >= 360.0 {
30 rotation -= 360.0; // Reset rotation after a full circle
31 }
32
33 if let Ok(mut cmd) = gpu.begin_command() {
34 if let Ok(mut gp) = cmd.begin_renderpass() {
35 gp.set_clear_color(Color::BLUE); // Set the clear color to blue
36
37 if let Some(mut drawing) = gp.begin_drawing() {
38 drawing.set_rotation(rotation); // Set rotation to 45 degrees
39 gp.set_blend(0, Some(&BlendState::ALPHA_BLEND));
40 drawing.draw_rect_filled(
41 Vector2::new(100.0, 100.0),
42 Vector2::new(200.0, 200.0),
43 Color::RED,
44 );
45
46 drawing.draw_circle_filled(Vector2::new(400.0, 300.0), 50.0, 25, Color::GREEN);
47
48 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
49
50 drawing.draw_text(
51 "Hello, World!",
52 Vector2::new(300.0, 500.0),
53 Color::WHITE,
54 );
55 }
56 }
57 }
58 }
59}Sourcepub fn draw_rect_image(&mut self, pos: Vector2, size: Vector2, color: Color)
pub fn draw_rect_image(&mut self, pos: Vector2, size: Vector2, color: Color)
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Font Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut font_manager = est_render::font::new();
18
19 let font = font_manager
20 .load_font("Arial", None, 20.0)
21 .expect("Failed to load font");
22
23 // Generate baked text texture
24 let texture = font
25 .create_baked_text(&mut gpu, "Hello, World!\nThis is a clear color example.", None)
26 .expect("Failed to create baked text");
27
28 while runner.pump_events(None) {
29 for event in runner.get_events() {
30 match event {
31 Event::WindowClosed { .. } => {
32 return;
33 }
34 _ => {}
35 }
36 }
37
38 if let Ok(mut cmd) = gpu.begin_command() {
39 if let Ok(mut gp) = cmd.begin_renderpass() {
40 gp.set_clear_color(Color::BLUE);
41
42 // The best texture blend for font rendering, others may has artifacts like black borders
43 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 let size: Vector2 = texture.size().into();
47
48 // Baked text rendering
49 drawing.set_texture(Some(&texture));
50 drawing.draw_rect_image(Vector2::new(0.0, 0.0), size, Color::WHITE);
51
52 // Online text rendering
53 drawing.set_font(&font);
54 drawing.draw_text(
55 "Hello, World!\nThis is a clear color example.",
56 Vector2::new(size.x, 0.0),
57 Color::WHITE,
58 );
59 }
60 }
61 }
62 }
63}More examples
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Clear Color Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let texture_atlas = gpu
18 .create_texture_atlas()
19 .add_texture_file(
20 "example_texture",
21 "./examples/resources/test1.png",
22 )
23 .add_texture_file(
24 "example_texture2",
25 "./examples/resources/test2.png",
26 )
27 .build()
28 .expect("Failed to create texture atlas");
29
30 while runner.pump_events(None) {
31 for event in runner.get_events() {
32 match event {
33 Event::WindowClosed { .. } => {
34 return;
35 }
36 _ => {}
37 }
38 }
39
40 if let Ok(mut cmd) = gpu.begin_command() {
41 if let Ok(mut gp) = cmd.begin_renderpass() {
42 gp.set_clear_color(Color::BLUEVIOLET);
43 gp.set_blend(0, Some(&BlendState::NONE));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 drawing.set_texture_atlas(Some((&texture_atlas, "example_texture")));
47 drawing.draw_rect_image(
48 Vector2::new(100.0, 100.0),
49 Vector2::new(200.0, 200.0),
50 Color::WHITE,
51 );
52 drawing.set_texture_atlas(Some((&texture_atlas, "example_texture2")));
53 drawing.draw_rect_image(
54 Vector2::new(350.0, 100.0),
55 Vector2::new(200.0, 200.0),
56 Color::WHITE,
57 );
58 drawing.draw_circle_image(Vector2::new(600.0, 200.0), 100.0, 20, Color::WHITE);
59 }
60 }
61 }
62 }
63}pub fn draw_rect_image_colors( &mut self, pos: Vector2, size: Vector2, color_tl: Color, color_tr: Color, color_br: Color, color_bl: Color, )
pub fn draw_triangle_image( &mut self, a: Vector2, b: Vector2, c: Vector2, color: Color, )
pub fn draw_triangle_image_colors( &mut self, a: Vector2, b: Vector2, c: Vector2, color_a: Color, color_b: Color, color_c: Color, )
Sourcepub fn draw_circle_image(
&mut self,
center: Vector2,
radius: f32,
segments: u32,
color: Color,
)
pub fn draw_circle_image( &mut self, center: Vector2, radius: f32, segments: u32, color: Color, )
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Clear Color Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let texture_atlas = gpu
18 .create_texture_atlas()
19 .add_texture_file(
20 "example_texture",
21 "./examples/resources/test1.png",
22 )
23 .add_texture_file(
24 "example_texture2",
25 "./examples/resources/test2.png",
26 )
27 .build()
28 .expect("Failed to create texture atlas");
29
30 while runner.pump_events(None) {
31 for event in runner.get_events() {
32 match event {
33 Event::WindowClosed { .. } => {
34 return;
35 }
36 _ => {}
37 }
38 }
39
40 if let Ok(mut cmd) = gpu.begin_command() {
41 if let Ok(mut gp) = cmd.begin_renderpass() {
42 gp.set_clear_color(Color::BLUEVIOLET);
43 gp.set_blend(0, Some(&BlendState::NONE));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 drawing.set_texture_atlas(Some((&texture_atlas, "example_texture")));
47 drawing.draw_rect_image(
48 Vector2::new(100.0, 100.0),
49 Vector2::new(200.0, 200.0),
50 Color::WHITE,
51 );
52 drawing.set_texture_atlas(Some((&texture_atlas, "example_texture2")));
53 drawing.draw_rect_image(
54 Vector2::new(350.0, 100.0),
55 Vector2::new(200.0, 200.0),
56 Color::WHITE,
57 );
58 drawing.draw_circle_image(Vector2::new(600.0, 200.0), 100.0, 20, Color::WHITE);
59 }
60 }
61 }
62 }
63}Sourcepub fn set_rotation(&mut self, rotation: f32)
pub fn set_rotation(&mut self, rotation: f32)
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Drawing Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut rotation = 0.0f32;
18 while runner.pump_events(None) {
19 for event in runner.get_events() {
20 match event {
21 Event::WindowClosed { .. } => {
22 return;
23 }
24 _ => {}
25 }
26 }
27
28 rotation += runner.get_frame_time() as f32 * 60.0f32; // Rotate at 60 degrees per second
29 if rotation >= 360.0 {
30 rotation -= 360.0; // Reset rotation after a full circle
31 }
32
33 if let Ok(mut cmd) = gpu.begin_command() {
34 if let Ok(mut gp) = cmd.begin_renderpass() {
35 gp.set_clear_color(Color::BLUE); // Set the clear color to blue
36
37 if let Some(mut drawing) = gp.begin_drawing() {
38 drawing.set_rotation(rotation); // Set rotation to 45 degrees
39 gp.set_blend(0, Some(&BlendState::ALPHA_BLEND));
40 drawing.draw_rect_filled(
41 Vector2::new(100.0, 100.0),
42 Vector2::new(200.0, 200.0),
43 Color::RED,
44 );
45
46 drawing.draw_circle_filled(Vector2::new(400.0, 300.0), 50.0, 25, Color::GREEN);
47
48 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
49
50 drawing.draw_text(
51 "Hello, World!",
52 Vector2::new(300.0, 500.0),
53 Color::WHITE,
54 );
55 }
56 }
57 }
58 }
59}pub fn get_rotation(&self) -> f32
pub fn set_scissor(&mut self, scissor: RectF)
pub fn set_viewport(&mut self, viewport: RectF)
Sourcepub fn set_texture(&mut self, texture: Option<&Texture>)
pub fn set_texture(&mut self, texture: Option<&Texture>)
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Font Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let mut font_manager = est_render::font::new();
18
19 let font = font_manager
20 .load_font("Arial", None, 20.0)
21 .expect("Failed to load font");
22
23 // Generate baked text texture
24 let texture = font
25 .create_baked_text(&mut gpu, "Hello, World!\nThis is a clear color example.", None)
26 .expect("Failed to create baked text");
27
28 while runner.pump_events(None) {
29 for event in runner.get_events() {
30 match event {
31 Event::WindowClosed { .. } => {
32 return;
33 }
34 _ => {}
35 }
36 }
37
38 if let Ok(mut cmd) = gpu.begin_command() {
39 if let Ok(mut gp) = cmd.begin_renderpass() {
40 gp.set_clear_color(Color::BLUE);
41
42 // The best texture blend for font rendering, others may has artifacts like black borders
43 gp.set_blend(0, Some(&BlendState::ADDITIVE_BLEND));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 let size: Vector2 = texture.size().into();
47
48 // Baked text rendering
49 drawing.set_texture(Some(&texture));
50 drawing.draw_rect_image(Vector2::new(0.0, 0.0), size, Color::WHITE);
51
52 // Online text rendering
53 drawing.set_font(&font);
54 drawing.draw_text(
55 "Hello, World!\nThis is a clear color example.",
56 Vector2::new(size.x, 0.0),
57 Color::WHITE,
58 );
59 }
60 }
61 }
62 }
63}pub fn set_texture_ex( &mut self, texture: Option<&Texture>, sampler: Option<TextureSampler>, )
pub fn set_texture_uv(&mut self, texture_uv: Option<RectF>)
Sourcepub fn set_texture_atlas(&mut self, atlas: Option<(&TextureAtlas, &str)>)
pub fn set_texture_atlas(&mut self, atlas: Option<(&TextureAtlas, &str)>)
Examples found in repository?
5fn main() {
6 let mut runner = est_render::runner::new().expect("Failed to create runner");
7
8 let mut window = runner
9 .create_window("Clear Color Example", Point2::new(800, 600))
10 .build()
11 .expect("Failed to create window");
12
13 let mut gpu = est_render::gpu::new(Some(&mut window))
14 .build()
15 .expect("Failed to create GPU");
16
17 let texture_atlas = gpu
18 .create_texture_atlas()
19 .add_texture_file(
20 "example_texture",
21 "./examples/resources/test1.png",
22 )
23 .add_texture_file(
24 "example_texture2",
25 "./examples/resources/test2.png",
26 )
27 .build()
28 .expect("Failed to create texture atlas");
29
30 while runner.pump_events(None) {
31 for event in runner.get_events() {
32 match event {
33 Event::WindowClosed { .. } => {
34 return;
35 }
36 _ => {}
37 }
38 }
39
40 if let Ok(mut cmd) = gpu.begin_command() {
41 if let Ok(mut gp) = cmd.begin_renderpass() {
42 gp.set_clear_color(Color::BLUEVIOLET);
43 gp.set_blend(0, Some(&BlendState::NONE));
44
45 if let Some(mut drawing) = gp.begin_drawing() {
46 drawing.set_texture_atlas(Some((&texture_atlas, "example_texture")));
47 drawing.draw_rect_image(
48 Vector2::new(100.0, 100.0),
49 Vector2::new(200.0, 200.0),
50 Color::WHITE,
51 );
52 drawing.set_texture_atlas(Some((&texture_atlas, "example_texture2")));
53 drawing.draw_rect_image(
54 Vector2::new(350.0, 100.0),
55 Vector2::new(200.0, 200.0),
56 Color::WHITE,
57 );
58 drawing.draw_circle_image(Vector2::new(600.0, 200.0), 100.0, 20, Color::WHITE);
59 }
60 }
61 }
62 }
63}pub fn set_texture_atlas_ex(&mut self, atlas: Option<(&TextureAtlas, &str)>)
pub fn set_shader(&mut self, shader: Option<&GraphicsShader>)
Trait Implementations§
Source§impl Clone for DrawingContext
impl Clone for DrawingContext
Source§fn clone(&self) -> DrawingContext
fn clone(&self) -> DrawingContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DrawingContext
impl Debug for DrawingContext
Auto Trait Implementations§
impl Freeze for DrawingContext
impl !RefUnwindSafe for DrawingContext
impl !Send for DrawingContext
impl !Sync for DrawingContext
impl Unpin for DrawingContext
impl !UnwindSafe for DrawingContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more