pub fn bake_to_texture(
    font: &Font,
    text: &str
) -> Result<(Texture, u32, u32), &'static str>
Expand description

Bakes the given text into a texture using the specified font and font size.

Note: This texture is not managed by the font object and the ownership of the texture is passed to the caller.

Arguments

  • font - The font to use for rendering the text.
  • text - The text to render.

Returns

Returns a tuple containing the resulting Texture object, as well as the width and height of the texture in pixels.

Example

cgl_rs::init();
let mut window = cgl_rs::Window::new("CGL Window", 800, 600).unwrap();
cgl_rs::graphics::init();
cgl_rs::graphics::text::init();
{
    let font = cgl_rs::graphics::text::Font::load("path/to/font.ttf").unwrap();
    let (texture, width, height) = cgl_rs::graphics::text::bake_to_texture(&font, "Hello, world!").unwrap();
    // Use the texture...
}
cgl_rs::graphics::text::shutdown();
cgl_rs::graphics::shutdown();
window.destroy();
cgl_rs::shutdown();