frug/
lib.rs

1//! FRUG is intended to provide a similar abstraction layer over graphics programming as to how SDL does for C++, meaning that it should provide developers enough control and flexibility to implement their own architectures & design patterns, yet simplifying the process of working with graphics so developers won't have to worry about implementing all the repetitive tasks related to getting things to the screen.
2//!
3//! Please see [the documentation](https://santyarellano.github.io/frug_book/) for more information.
4//!
5//! I'M MIGRATING THIS WHOLE THING FROM WGPU TO SDL3. PLEASE HOLD ON!!!
6
7mod instance;
8mod sprite;
9mod vectors;
10
11pub use instance::Instance;
12pub use sdl3;
13pub use sdl3::event::Event;
14pub use sdl3::event::EventPollIterator;
15pub use sdl3::image::LoadTexture;
16pub use sdl3::keyboard::Keycode;
17pub use sdl3::pixels::Color;
18pub use sdl3::rect::Rect;
19pub use sdl3::render;
20pub use sdl3::render::ScaleMode;
21pub use sdl3::render::TextureQuery;
22pub use sdl3::ttf;
23pub use sdl3::video;
24pub use sprite::Sprite;
25pub use vectors::Vec2d;
26
27/// Creates a texture from a given font and a given text.
28/// `font` - The font to use.
29/// `text` - The text to render.
30/// `color` - The color of the text.
31/// `texture_creator` - The texture creator to use.
32pub fn create_text_texture<'a>(
33    font: &ttf::Font,
34    text: &str,
35    color: &Color,
36    texture_creator: &'a render::TextureCreator<video::WindowContext>,
37) -> Result<render::Texture<'a>, String> {
38    let surface = match font.render(text).blended(*color) {
39        Ok(surface) => surface,
40        Err(e) => return Err(format!("Failed to create surface for text texture: {}", e)),
41    };
42
43    let texture = texture_creator
44        .create_texture_from_surface(&surface)
45        .map_err(|e| format!("Failed to create text texture from surface: {}", e))?;
46
47    Ok(texture)
48}