Skip to content

Addon for the minifb crate that enables drawing text using bitmap fonts

License

Notifications You must be signed in to change notification settings

bhavyakukkar/rust_minifb_fonts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minifb_fonts

Simple Addon for the minifb crate that enables drawing text using bitmap fonts.

Example

Usage

Add this to your Cargo.toml:

[dependencies]
minifb_fonts = "0.1"

Example

use minifb::{WindowOptions, Scale, Window};
use minifb_fonts::*;

fn main() {
    const WINDOW_WIDTH: usize = 400;
    const WINDOW_HEIGHT: usize = 200;

    let mut buffer: Vec<u32> = vec![0; WINDOW_WIDTH * WINDOW_HEIGHT];

    let text = font5x8::new_renderer(WINDOW_WIDTH, WINDOW_HEIGHT, color);
    text.draw_text(&mut buffer, 10, 20, "Hello World!");
    text.set_color(0xff_00_00);
    text.draw_text(&mut buffer, 10, 180, "Press ESC to exit");

    // minifb window initialization
    let mut window = Window::new("minifb Font - ESC to exit", WINDOW_WIDTH, WINDOW_HEIGHT,
    WindowOptions {
        scale: Scale::X2,
        ..WindowOptions::default()
    }).unwrap();

    while window.is_open() && !window.is_key_down(minifb::Key::Escape) {
        window.update_with_buffer(&buffer, WINDOW_WIDTH, WINDOW_HEIGHT).unwrap();
    }
}

Examples

cargo build
cargo run --example draw_text

This will run draw text example.

Find more exaples here

License

About

Addon for the minifb crate that enables drawing text using bitmap fonts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%