1#![allow(unused)]
2
3pub use crate::camera::camera2d::Camera2D;
6pub use crate::camera::render_target::RenderTarget;
7use crate::draw_state::shapes::Shape;
8pub use crate::draw_state::shapes::color::*;
9pub use crate::end_frame;
10use crate::global::{PENDING_CONFIG, STATE, ctx};
11pub use crate::misc::flake_image::Image;
12use crate::misc::font::Font;
13pub use crate::misc::math::*;
14pub use crate::misc::rect::Rect;
15use crate::misc::span::RichtextSection;
16pub use crate::misc::span::Span;
17pub use crate::misc::timer::Timer;
18pub use crate::misc::*;
19use crate::model::instance::Instance;
20pub use crate::model::texture::DrawTextureParams;
21pub use crate::model::texture::FilterType;
22use crate::model::texture::{GpuTexture, Texture};
23pub use crate::runtime::next_frame::next_frame;
24pub use crate::{FlakeResult, flake};
25use image::{DynamicImage, GenericImageView, ImageBuffer, Rgb, Rgba};
26use std::borrow::Borrow;
27use std::sync::Arc;
28pub use winit::event::MouseButton;
29pub use winit::keyboard::KeyCode;
30#[cfg(target_os = "windows")]
31use winit::platform::windows::WindowExtWindows;
32use winit::window::Window;
33pub use winit::window::{CursorIcon, WindowButtons, WindowLevel};
34pub fn flake_quit() {
44 ctx(|s| s.exit())
45}
46
47pub fn flake_sleep(seconds: f32) {
58 std::thread::sleep(std::time::Duration::from_secs_f32(seconds));
59}
60
61pub fn add_timer(timer: Timer) -> Timer {
73 if STATE.get().is_some() {
74 return ctx(|s| {
75 if !s.timers.contains(&timer) {
76 s.add_timer(timer.clone());
77 }
78 timer
79 });
80 }
81
82 PENDING_CONFIG.with_borrow_mut(|s| {
83 if !s.timers.contains(&timer) {
84 s.timers.push(timer.clone())
85 }
86 });
87
88 timer
89}
90
91pub fn get_window() -> Arc<Window> {
100 ctx(|s| s.get_window())
101}
102
103pub fn set_window_passthrough(passthrough: bool) {
105 if STATE.get().is_some() {
106 return ctx(|s| s.set_window_passthrough(passthrough));
107 }
108
109 PENDING_CONFIG.with_borrow_mut(|s| s.window_passthrough = Some(passthrough));
110}
111
112pub fn set_window_level(level: WindowLevel) {
114 if STATE.get().is_some() {
115 return ctx(|s| s.set_window_level(level));
116 }
117
118 PENDING_CONFIG.with_borrow_mut(|s| s.window_level = Some(level));
119}
120
121pub fn set_window_enabled_buttons(window_buttons: WindowButtons) {
124 ctx(|s| s.get_window().set_enabled_buttons(window_buttons));
125}
126
127pub fn set_skip_taskbar(skip: bool) {
129 if STATE.get().is_some() {
130 #[cfg(target_os = "windows")]
131 return ctx(|s| s.window.set_skip_taskbar(skip));
132 }
133
134 PENDING_CONFIG.with_borrow_mut(|s| s.skip_taskbar = Some(skip));
135}
136
137pub fn set_window_transparent(transparent: bool) {
140 if STATE.get().is_some() {
141 return get_window().set_transparent(transparent);
142 }
143
144 PENDING_CONFIG.with_borrow_mut(|s| s.window_transparent = Some(transparent));
145}
146
147pub fn set_window_decorations(enabled: bool) {
149 if STATE.get().is_some() {
150 return get_window().set_decorations(enabled);
151 }
152
153 PENDING_CONFIG.with_borrow_mut(|s| s.window_decorations = Some(enabled));
154}
155
156pub fn set_window_title(title: &str) {
166 if STATE.get().is_some() {
167 return ctx(|s| s.set_window_title(title));
168 }
169
170 PENDING_CONFIG.with_borrow_mut(|s| s.window_title = Some(title.into()));
171}
172
173pub fn set_window_visible(visible: bool) {
182 if STATE.get().is_some() {
183 return ctx(|s| s.set_window_visible(visible));
184 }
185
186 PENDING_CONFIG.with_borrow_mut(|s| s.window_visible = Some(visible));
187}
188
189pub fn set_window_icon(path: &str) {
197 let img = image::open(path)
198 .expect("image icon does not exist at path")
199 .into_rgba8();
200 let (width, height) = img.dimensions();
201 let rgba = img.into_raw();
202
203 if STATE.get().is_some() {
204 return ctx(|s| s.set_window_icon(rgba, width, height));
205 }
206
207 PENDING_CONFIG.with_borrow_mut(|s| s.window_icon = Some((rgba, width, height)));
208}
209
210pub fn set_window_icon_bytes(bytes: &[u8]) {
212 let img = image::load_from_memory(bytes)
213 .expect("image icon does not exist at path")
214 .into_rgba8();
215 let (width, height) = img.dimensions();
216 let rgba = img.into_raw();
217
218 if STATE.get().is_some() {
219 return ctx(|s| s.set_window_icon(rgba, width, height));
220 }
221
222 PENDING_CONFIG.with_borrow_mut(|s| s.window_icon = Some((rgba, width, height)));
223}
224
225pub fn set_window_x(x: i32) {
233 if STATE.get().is_some() {
234 return ctx(|s| s.set_window_x(x));
235 }
236
237 PENDING_CONFIG.with_borrow_mut(|s| s.window_x = Some(x));
238}
239
240pub fn set_window_y(y: i32) {
248 if STATE.get().is_some() {
249 return ctx(|s| s.set_window_y(y));
250 }
251
252 PENDING_CONFIG.with_borrow_mut(|s| s.window_y = Some(y));
253}
254
255pub fn set_window_position(x: i32, y: i32) {
263 set_window_x(x);
264 set_window_y(y);
265}
266
267pub fn window_width() -> f32 {
269 ctx(|s| s.window_width())
270}
271
272pub fn window_height() -> f32 {
274 ctx(|s| s.window_height())
275}
276
277pub fn window_size() -> Vector2 {
279 ctx(|s| Vector2::new(s.window_width(), s.window_height()))
280}
281
282pub fn window_position() -> (f32, f32) {
284 ctx(|s| s.window_position())
285}
286
287pub fn window_position_vec2() -> Vector2 {
289 ctx(|s| s.window_position().into())
290}
291
292pub fn window_x() -> f32 {
294 ctx(|s| s.window_x())
295}
296
297pub fn window_y() -> f32 {
299 ctx(|s| s.window_y())
300}
301
302pub fn set_window_width(w: u32) {
310 if STATE.get().is_some() {
311 return ctx(|s| s.set_window_w(w));
312 }
313
314 PENDING_CONFIG.with_borrow_mut(|s| s.window_width = Some(w));
315}
316
317pub fn set_window_height(h: u32) {
325 if STATE.get().is_some() {
326 return ctx(|s| s.set_window_h(h));
327 }
328
329 PENDING_CONFIG.with_borrow_mut(|s| s.window_height = Some(h));
330}
331
332pub fn set_window_size(w: u32, h: u32) {
340 if STATE.get().is_some() {
341 return ctx(|s| s.set_window_size(w, h));
342 }
343
344 PENDING_CONFIG.with_borrow_mut(|s| {
345 s.window_width = Some(w);
346 s.window_height = Some(h);
347 });
348}
349
350pub fn set_window_resizable(resizeable: bool) {
352 ctx(|s| s.window.set_resizable(resizeable));
353}
354
355pub fn get_fps() -> f32 {
366 ctx(|s| s.get_fps())
367}
368
369pub fn set_target_fps(fps: usize) {
377 if STATE.get().is_some() {
378 return ctx(|s| s.set_target_fps(fps));
379 }
380
381 PENDING_CONFIG.with_borrow_mut(|s| s.target_fps = Some(fps));
382}
383
384pub fn set_fps_capped(capped: bool) {
393 if STATE.get().is_some() {
394 return ctx(|s| s.set_fps_capped(capped));
395 }
396
397 PENDING_CONFIG.with_borrow_mut(|s| s.fps_capped = Some(capped));
398}
399
400pub fn get_frame_time() -> f32 {
409 ctx(|s| s.get_frame_time())
410}
411
412pub fn get_frames() -> usize {
421 ctx(|s| s.get_frames())
422}
423
424pub fn mouse_position() -> (f32, f32) {
434 ctx(|s| s.mouse_state.get_position().into())
435}
436
437pub fn mouse_position_vec2() -> Vector2 {
446 ctx(|s| s.mouse_state.get_position())
447}
448
449pub fn mouse_screen_position_vec2() -> Vector2 {
451 ctx(|s| s.mouse_state.get_screen_position())
452}
453
454pub fn mouse_screen_position() -> (f32, f32) {
456 ctx(|s| s.mouse_state.get_screen_position().into())
457}
458
459pub fn mouse_wheel() -> Vector2 {
468 ctx(|s| s.mouse_state.get_mouse_wheel())
469}
470
471pub fn set_mouse_icon(cursor_icon: CursorIcon) {
479 ctx(|s| s.window.set_cursor(cursor_icon))
480}
481pub fn focus_window() {
483 get_window().focus_window();
484}
485
486pub fn is_mouse_button_down(btn: MouseButton) -> bool {
497 ctx(|s| s.mouse_state.is_button_down(btn))
498}
499
500pub fn is_mouse_button_pressed(btn: MouseButton) -> bool {
510 ctx(|s| s.mouse_state.is_button_pressed(btn))
511}
512
513pub fn is_mouse_button_released(btn: MouseButton) -> bool {
524 ctx(|s| s.mouse_state.is_button_released(btn))
525}
526
527pub fn is_key_down(key: KeyCode) -> bool {
536 ctx(|s| s.keyboard_state.is_key_down(key))
537}
538
539pub fn is_key_pressed(key: KeyCode) -> bool {
549 ctx(|s| s.keyboard_state.is_key_pressed(key))
550}
551
552pub fn is_key_released(key: KeyCode) -> bool {
562 ctx(|s| s.keyboard_state.is_key_released(key))
563}
564
565pub fn get_axis(left: KeyCode, right: KeyCode) -> f32 {
567 ctx(|s| match (is_key_down(left), is_key_down(right)) {
568 (true, false) => -1.0,
569 (false, true) => 1.0,
570 _ => 0.0,
571 })
572}
573
574pub fn get_vector(left: KeyCode, right: KeyCode, up: KeyCode, down: KeyCode) -> Vector2 {
577 ctx(|s| {
578 Vector2::new(
579 match (is_key_down(left), is_key_down(right)) {
580 (true, false) => -1.0,
581 (false, true) => 1.0,
582 _ => 0.0,
583 },
584 match (is_key_down(up), is_key_down(down)) {
585 (true, false) => -1.0,
586 (false, true) => 1.0,
587 _ => 0.0,
588 },
589 )
590 })
591}
592
593pub fn clear_background(color: Color) {
604 if STATE.get().is_some() {
605 return ctx(|s| {
606 s.clear_color = Some(color);
607 s.draw_state.clear();
608 });
609 }
610
611 PENDING_CONFIG.with_borrow_mut(|c| c.window_clear_color = Some(color));
612}
613
614pub fn draw_rectangle(x: f32, y: f32, w: f32, h: f32, color: Color) {
623 draw_rectangle_rounded(x, y, w, h, 0.0, color);
624}
625
626pub fn draw_rectangle_rounded(x: f32, y: f32, w: f32, h: f32, radius: f32, color: Color) {
635 draw_rectangle_rounded_ex(x, y, w, h, radius, radius, radius, radius, color)
636}
637
638pub fn draw_rectangle_rounded_ex(
653 x: f32,
654 y: f32,
655 w: f32,
656 h: f32,
657 top_left: f32,
658 top_right: f32,
659 bottom_left: f32,
660 bottom_right: f32,
661 color: Color,
662) {
663 ctx(|s| {
664 s.draw_state.draw_rectangle(
665 x,
666 y,
667 w,
668 h,
669 top_left,
670 top_right,
671 bottom_left,
672 bottom_right,
673 color,
674 )
675 });
676}
677
678pub fn draw_rectangle_from_rect(rect: Rect, color: Color) {
686 draw_rectangle(rect.x, rect.y, rect.w, rect.h, color);
687}
688
689pub fn draw_rectangle_rounded_from_rect(rect: Rect, radius: f32, color: Color) {
698 draw_rectangle_rounded(rect.x, rect.y, rect.w, rect.h, radius, color);
699}
700
701pub fn draw_rectangle_lines_rounded_from_rect(
710 rect: Rect,
711 radius: f32,
712 thickness: f32,
713 color: Color,
714) {
715 draw_rectangle_lines_rounded(rect.x, rect.y, rect.w, rect.h, radius, thickness, color);
716}
717
718pub fn draw_rectangle_lines_rounded_from_rect_ex(
727 rect: Rect,
728 top_left: f32,
729 top_right: f32,
730 bottom_left: f32,
731 bottom_right: f32,
732 thickness: f32,
733 color: Color,
734) {
735 draw_rectangle_lines_rounded_ex(
736 rect.x,
737 rect.y,
738 rect.w,
739 rect.h,
740 top_left,
741 top_right,
742 bottom_left,
743 bottom_right,
744 thickness,
745 color,
746 );
747}
748
749pub fn draw_rectangle_rounded_from_rect_ex(
763 rect: Rect,
764 top_left: f32,
765 top_right: f32,
766 bottom_left: f32,
767 bottom_right: f32,
768 color: Color,
769) {
770 draw_rectangle_rounded_ex(
771 rect.x,
772 rect.y,
773 rect.w,
774 rect.h,
775 top_left,
776 top_right,
777 bottom_left,
778 bottom_right,
779 color,
780 );
781}
782
783pub fn draw_rectangle_lines(x: f32, y: f32, w: f32, h: f32, thickness: f32, color: Color) {
791 draw_rectangle_lines_rounded(x, y, w, h, 0.0, thickness, color)
792}
793
794pub fn draw_rectangle_lines_from_rect(rect: Rect, thickness: f32, color: Color) {
802 draw_rectangle_lines(rect.x, rect.y, rect.w, rect.h, thickness, color);
803}
804
805pub fn draw_rectangle_lines_rounded(
816 x: f32,
817 y: f32,
818 w: f32,
819 h: f32,
820 radius: f32,
821 thickness: f32,
822 color: Color,
823) {
824 draw_rectangle_lines_rounded_ex(x, y, w, h, radius, radius, radius, radius, thickness, color);
825}
826
827pub fn draw_rectangle_lines_rounded_ex(
842 x: f32,
843 y: f32,
844 w: f32,
845 h: f32,
846 top_left: f32,
847 top_right: f32,
848 bottom_left: f32,
849 bottom_right: f32,
850 thickness: f32,
851 color: Color,
852) {
853 ctx(|s| {
854 s.draw_state.draw_rectangle_lines(
855 x,
856 y,
857 w,
858 h,
859 top_left,
860 top_right,
861 bottom_left,
862 bottom_right,
863 thickness,
864 color,
865 )
866 });
867}
868
869pub fn draw_rectangle_rotated(x: f32, y: f32, w: f32, h: f32, rotation: f32, color: Color) {
878 ctx(|s| {
879 s.draw_state
880 .draw_rectangle_rotated(x, y, w, h, rotation, 0.0, 0.0, 0.0, 0.0, color)
881 });
882}
883
884pub fn draw_rectangle_lines_rotated(
887 x: f32,
888 y: f32,
889 w: f32,
890 h: f32,
891 rotation: f32,
892 thickness: f32,
893 color: Color,
894) {
895 ctx(|s| {
896 s.draw_state.draw_rectangle_lines_rotated(
897 x, y, w, h, rotation, 0.0, 0.0, 0.0, 0.0, thickness, color,
898 )
899 });
900}
901
902pub fn draw_rectangle_rounded_rotated(
906 x: f32,
907 y: f32,
908 w: f32,
909 h: f32,
910 rotation: f32,
911 radius: f32,
912 color: Color,
913) {
914 draw_rectangle_rounded_rotated_ex(x, y, w, h, rotation, radius, radius, radius, radius, color);
915}
916
917pub fn draw_rectangle_rounded_rotated_ex(
918 x: f32,
919 y: f32,
920 w: f32,
921 h: f32,
922 rotation: f32,
923 top_left: f32,
924 top_right: f32,
925 bottom_left: f32,
926 bottom_right: f32,
927 color: Color,
928) {
929 ctx(|s| {
930 s.draw_state.draw_rectangle_rotated(
931 x,
932 y,
933 w,
934 h,
935 rotation,
936 top_left,
937 top_right,
938 bottom_left,
939 bottom_right,
940 color,
941 )
942 });
943}
944
945pub fn draw_rectangle_lines_rounded_rotated(
949 x: f32,
950 y: f32,
951 w: f32,
952 h: f32,
953 rotation: f32,
954 radius: f32,
955 thickness: f32,
956 color: Color,
957) {
958 draw_rectangle_lines_rounded_rotated_ex(
959 x, y, w, h, rotation, radius, radius, radius, radius, thickness, color,
960 );
961}
962
963pub fn draw_rectangle_lines_rounded_rotated_ex(
967 x: f32,
968 y: f32,
969 w: f32,
970 h: f32,
971 rotation: f32,
972 top_left: f32,
973 top_right: f32,
974 bottom_left: f32,
975 bottom_right: f32,
976 thickness: f32,
977 color: Color,
978) {
979 ctx(|s| {
980 s.draw_state.draw_rectangle_lines_rotated(
981 x,
982 y,
983 w,
984 h,
985 rotation,
986 top_left,
987 top_right,
988 bottom_left,
989 bottom_right,
990 thickness,
991 color,
992 )
993 });
994}
995
996pub fn draw_circle(x: f32, y: f32, r: f32, color: Color) {
1004 ctx(|s| s.draw_state.draw_circle(x, y, r, color));
1005}
1006
1007pub fn draw_circle_lines(x: f32, y: f32, r: f32, thickness: f32, color: Color) {
1016 ctx(|s| s.draw_state.draw_circle_lines(x, y, r, thickness, color));
1017}
1018
1019pub fn draw_triangle(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: Color) {
1028 ctx(|s| s.draw_state.draw_triangle(x1, y1, x2, y2, x3, y3, color));
1029}
1030
1031pub fn draw_triangle_lines(
1040 x1: f32,
1041 y1: f32,
1042 x2: f32,
1043 y2: f32,
1044 x3: f32,
1045 y3: f32,
1046 thickness: f32,
1047 color: Color,
1048) {
1049 ctx(|s| {
1050 s.draw_state
1051 .draw_triangle_lines(x1, y1, x2, y2, x3, y3, thickness, color)
1052 });
1053}
1054
1055pub fn draw_line(x1: f32, y1: f32, x2: f32, y2: f32, thickness: f32, color: Color) {
1064 ctx(|s| s.draw_state.draw_line(x1, y1, x2, y2, thickness, color))
1065}
1066
1067pub fn draw_poly_line(points: &[Vector2], thickness: f32, color: Color, closed: bool) {
1078 ctx(|s| {
1079 s.draw_state
1080 .draw_poly_line_miter(points, thickness, color, closed)
1081 })
1082}
1083
1084pub fn draw_poly_line_rounded(points: &[Vector2], thickness: f32, color: Color, closed: bool) {
1095 ctx(|s| {
1096 s.draw_state
1097 .draw_poly_line(points, thickness, color, closed, true)
1098 })
1099}
1100
1101pub fn draw_polygon(points: &[Vector2], color: Color) {
1114 ctx(|s| s.draw_state.draw_polygon(points, color))
1115}
1116
1117pub fn draw_polygon_concave(points: &[Vector2], color: Color) {
1131 ctx(|s| s.draw_state.draw_polygon_concave(points, color))
1132}
1133
1134pub fn draw_text(t: &str, x: f32, y: f32, size: f32, font: Option<&Font>, color: Color) {
1143 ctx(|s| s.draw_state.draw_text(&s.fonts, t, x, y, size, font, color));
1144}
1145
1146pub fn draw_rich_text<'a, I>(
1165 position: Vector2,
1166 size: f32,
1167 font: Option<&Font>,
1168 color: Color,
1169 spans: I,
1170) where
1171 I: IntoIterator,
1172 I::Item: Borrow<Span<'a>>,
1173{
1174 ctx(|s| {
1175 s.draw_state
1176 .draw_richtext(position, size, font, color, spans)
1177 })
1178}
1179
1180pub fn load_font_from_path(path: &str) -> Font {
1194 if STATE.get().is_some() {
1195 return ctx(|s| {
1196 s.load_font_from_path(path);
1197 s.fonts[s.fonts.len() - 1].clone()
1198 });
1199 }
1200
1201 PENDING_CONFIG.with_borrow_mut(|s| {
1202 let font = Font::from_path(s.fonts.len() + 1, path);
1203 s.fonts.push(font.clone());
1204 font
1205 })
1206}
1207
1208pub fn load_font_from_bytes(bytes: &[u8]) -> Font {
1222 if STATE.get().is_some() {
1223 return ctx(|s| {
1224 s.load_font_from_bytes(bytes);
1225 s.fonts[s.fonts.len() - 1].clone()
1226 });
1227 }
1228
1229 PENDING_CONFIG.with_borrow_mut(|s| {
1230 let font = Font::from_bytes(s.fonts.len() + 1, bytes);
1231 s.fonts.push(font.clone());
1232 font
1233 })
1234}
1235
1236pub fn measure_text(t: &str, size: f32, font: Option<&Font>) -> Vector2 {
1238 let (w, h) = ctx(|s| s.measure_text(t, size, font));
1239 Vector2::new(w, h)
1240}
1241
1242pub fn draw_arrow(
1245 x1: f32,
1246 y1: f32,
1247 x2: f32,
1248 y2: f32,
1249 thickness: f32,
1250 head_size: f32,
1251 color: Color,
1252) {
1253 ctx(|s| {
1254 s.draw_state
1255 .draw_arrow(x1, y1, x2, y2, thickness, head_size, color)
1256 });
1257}
1258
1259pub fn screen_size() -> Vector2 {
1261 let win = get_window();
1262 match win.current_monitor() {
1263 Some(m) => {
1264 let s = m.size();
1265 Vector2::new(s.width as f32, s.height as f32)
1266 }
1267 None => window_size(),
1268 }
1269}
1270
1271pub fn screen_width() -> f32 {
1272 screen_size().x
1273}
1274pub fn screen_height() -> f32 {
1275 screen_size().y
1276}
1277
1278pub fn create_empty_texture(width: u32, height: u32, filter_type: FilterType) -> Texture {
1282 ctx(|s| {
1283 let gpu = GpuTexture::empty(
1284 &s.device,
1285 width,
1286 height,
1287 filter_type,
1288 wgpu::TextureFormat::Rgba8UnormSrgb,
1289 )
1290 .expect("Couldn't create empty GpuTexture");
1291
1292 Texture {
1293 id: s.add_gpu_texture(gpu, false),
1294 width,
1295 height,
1296 }
1297 })
1298}
1299
1300pub fn load_texture(path: &str) -> Texture {
1302 ctx(|s| {
1303 let image = image::load_from_memory(&std::fs::read(path).unwrap()).unwrap();
1304 let width = image.width();
1305 let height = image.height();
1306
1307 Texture {
1308 id: s.add_texture(image, FilterType::Linear),
1309 width,
1310 height,
1311 }
1312 })
1313}
1314
1315pub fn load_texture_with_filter_type(path: &str, filter_type: FilterType) -> Texture {
1317 ctx(|s| {
1318 let image = image::load_from_memory(&std::fs::read(path).unwrap()).unwrap();
1319 let width = image.width();
1320 let height = image.height();
1321
1322 Texture {
1323 id: s.add_texture(image, filter_type),
1324 width,
1325 height,
1326 }
1327 })
1328}
1329
1330pub fn load_texture_from_bytes(bytes: &[u8]) -> Texture {
1332 ctx(|s| {
1333 let image = image::load_from_memory(bytes).unwrap();
1334 let (width, height) = image.dimensions();
1335
1336 Texture {
1337 id: s.add_texture(image, FilterType::Linear),
1338 width,
1339 height,
1340 }
1341 })
1342}
1343
1344pub fn load_texture_from_bytes_with_filter_type(bytes: &[u8], filter_type: FilterType) -> Texture {
1346 ctx(|s| {
1347 let image = image::load_from_memory(bytes).unwrap();
1348 let (width, height) = image.dimensions();
1349
1350 Texture {
1351 id: s.add_texture(image, filter_type),
1352 width,
1353 height,
1354 }
1355 })
1356}
1357
1358pub fn load_texture_from_data(width: u32, height: u32, data: &[f32]) -> Texture {
1360 ctx(|s| {
1361 let img_buf = ImageBuffer::<Rgba<f32>, Vec<f32>>::from_raw(width, height, data.to_vec())
1362 .expect("Buffer size mismatch");
1363
1364 let dynamic_img = DynamicImage::ImageRgba32F(img_buf);
1365
1366 Texture {
1367 id: s.add_texture(dynamic_img, FilterType::Linear),
1368 width,
1369 height,
1370 }
1371 })
1372}
1373
1374pub fn load_texture_from_data_with_filter_type(
1378 width: u32,
1379 height: u32,
1380 data: &[f32],
1381 filter_type: FilterType,
1382) -> Texture {
1383 ctx(|s| {
1384 let img_buf = ImageBuffer::<Rgba<f32>, Vec<f32>>::from_raw(width, height, data.to_vec())
1385 .expect("Buffer size mismatch");
1386
1387 let dynamic_img = DynamicImage::ImageRgba32F(img_buf);
1388
1389 Texture {
1390 id: s.add_texture(dynamic_img, filter_type),
1391 width,
1392 height,
1393 }
1394 })
1395}
1396
1397pub fn load_texture_from_image(image: &Image) -> Texture {
1399 let tex = create_empty_texture(image.width, image.height, image.filter_type);
1400 update_texture(tex, image);
1401
1402 tex
1403}
1404
1405pub fn draw_texture(texture: Texture, x: f32, y: f32, w: f32, h: f32, tint: Color) {
1408 ctx(|s| s.draw_state.draw_texture(texture, x, y, w, h, tint))
1409}
1410
1411pub fn draw_texture_ex(texture: Texture, x: f32, y: f32, p: DrawTextureParams) {
1414 ctx(|s| s.draw_state.draw_texture_ex(texture, x, y, p))
1415}
1416
1417pub fn update_texture(texture: Texture, image: &Image) {
1419 ctx(|s| s.update_texture(texture.id, image))
1420}
1421
1422pub fn render_target(width: u32, height: u32, filter_type: FilterType) -> RenderTarget {
1424 ctx(|s| s.create_render_target(width, height, filter_type))
1425}
1426
1427pub fn set_camera(cam: &Camera2D) {
1429 ctx(|s| s.set_camera(cam))
1430}
1431
1432pub fn set_default_camera() {
1434 ctx(|s| s.set_default_camera())
1435}