Struct webgl2_glyph::TextRenderer [−][src]
pub struct TextRenderer { /* fields omitted */ }
Expand description
Glyph renderer for WebGL2.
Example usage:
use wasm_bindgen::JsCast;
use web_sys::WebGl2RenderingContext;
use webgl2_glyph::{TextRenderer, glyph_brush::{FontArc, Section, Text}};
let document = web_sys::window().unwrap().document().unwrap();
let canvas = document.get_element_by_id("canvas").unwrap();
let canvas: web_sys::HtmlCanvasElement =
canvas.dyn_into::<web_sys::HtmlCanvasElement>().unwrap();
let gl = canvas
.get_context("webgl2")
.unwrap()
.unwrap()
.dyn_into::<WebGl2RenderingContext>()
.unwrap();
let font =
FontArc::try_from_slice(include_bytes!("../demos/SourceSansPro-Regular.ttf")).unwrap();
let mut renderer = TextRenderer::try_new(&gl, font).unwrap();
renderer.glyph_brush().queue(
Section::default()
.add_text(Text::new("Hello world").with_scale(50.))
.with_screen_position((30., 30.)),
);
renderer.render().unwrap();
Implementations
Returns a mutable reference to the renderer’s internal GlyphBrush
instance.
This can be used to add text to the queue.
Construct a new instance for rendering text in the given font to the given WebGL2 rendering context.