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.

Render the queued text. Should be called from a request_animation_frame callback. Rendering clears the draw queue.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.