PistonDevelopers/graphics

How should a GlyphCache be created?

malikolivier opened this issue · 2 comments

A method GlyphCache::from_font is defined here.

I would like to use it, but I cannot fathom what should be provided as the factory argument.
Here is what guess and trial and error has led me to until now:

extern crate texture;
extern crate rusttype;
extern crate graphics;
use graphics::glyph_cache::rusttype::GlyphCache;

// Load font
let font_data = include_bytes!("/path_to_font/font.ttf");
let font = rusttype::FontCollection::from_bytes(font_data as &[u8]).into_font().unwrap();

// Use default texture settings
let settings = texture::TextureSettings::new();

// Make glyph cache factory. What should I do????
let factory = ?????;

// Make glyph cache
let cache = GlyphCache::from_font(font, factory, settings);

My ultimate objective is to use the text function defined here in order to draw text. Maybe I am doing it the wrong way, but an example or some resources would be very welcome!

I am currently writing a lib using piston2d-graphics as one of its backend, and I plan to contribute back to the piston doc.

Thank you very much! I missed the example you just gave to me.

I see that for the opengl_graphics backend, it's enough to pass () as a factory, as the trait CreateTexture<()> is defined there.

You could actually create a glyph cache just with:

use opengl_graphics::{GlyphCache, TextureSettings};

let cache = GlyphCache::new("/path_to_font/font.ttf", (), TextureSettings::new())?