Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deifactor/extol_image_font
Render pixel fonts from PNGs in Bevy.
https://github.com/deifactor/extol_image_font
bevy rust
Last synced: 2 months ago
JSON representation
Render pixel fonts from PNGs in Bevy.
- Host: GitHub
- URL: https://github.com/deifactor/extol_image_font
- Owner: deifactor
- License: apache-2.0
- Created: 2023-07-18T01:58:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-05T00:17:32.000Z (9 months ago)
- Last Synced: 2024-09-27T07:04:27.782Z (3 months ago)
- Topics: bevy, rust
- Language: Rust
- Homepage:
- Size: 49.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
`extol_image_font` allows rendering fonts that are stored as a single image (typically PNG), with each letter at a given location. This is common in game development, especially for pixel art fonts, since it allows the use of colors and creating a font can be done using any image editor as opposed to specialized software. These are also sometimes known as 'pixel fonts', but I choose the name 'image font' to be more precise (since bitmap fonts stored in OTB could also be called 'pixel fonts').
## Features
**Supported**
- Unicode (anything that fits in a single codepoint)
- Specifying the coordinates with a string containing the letters in proper order (see the example asset)
- Manually specifying the rects (including non-uniform sizes)**Future work**
- Padding and offsets for automatic texture layout
- Newlines embedding in strings**Out of scope**
- Rendering from 'actual' bitmap fonts
- Automatic line wrapping### Caveats
- You need to have a portion of the texture that's just blank and 'map' the space character to it.
- Newlines are not currently supported.## How to use
**Note that for pixel-accurate rendering, locating the text at integer coordinates 'in the world' can cause it to be blurry.** I'm not sure why. If this happens, you'll want to offset the x/y coordinates by a small amount like 0.1. This seems to be less of an issue using this crate with bevy_ui.
Just take any entity with a `Handle` or `UiImage` component, such as something created with a `SpriteBundle` or `ImageBundle`, and add a `ImageFontText` component to it.
See [the bevy_ui example] for sample usage using the `bevy_asset_loader` crate to construct handles to the texture layout and image, or [the sprite example] if you want to use pixel fonts 'in the world' (such as for flying damage text).
[the sprite example]: https://github.com/deifactor/extol_image_font/blob/main/examples/sprite.rs
[the bevy_ui example]: https://github.com/deifactor/extol_image_font/blob/main/examples/bevy_ui.rsIf you're not using `bevy_ui`, you can disable the `bevy_ui` feature (enabled by default) to avoid taking a dependency on that.
This crate uses the `image` crate to load images, but only enables PNG support by default. If you need some other format, add your own dependency on (the same version of) `image` and enable the relevant features.
## How it works
## Credits
The sample font is by [gnsh](https://opengameart.org/content/bitmap-font-0).