pub struct GlBackendBuilder { /* private fields */ }Expand description
Builder for the GL backend.
§Examples
use retroglyph_core::color::Style;
use retroglyph_gl::GlBackendBuilder;
use retroglyph_window::winit::{WindowConfig, run_windowed};
let renderer = GlBackendBuilder::new()
.grid_size(80, 25)
.scale(2)
.build()
.expect("gl backend init failed");
let config = WindowConfig::fit(&renderer, "My Game", None, true);
run_windowed(config, renderer, move |term| {
term.draw(|s| s.print((0, 0), "Hello from retroglyph-gl!", Style::default()))
.ok();
})
.expect("event loop failed");Implementations§
Source§impl GlBackendBuilder
impl GlBackendBuilder
Sourcepub const fn new() -> Self
pub const fn new() -> Self
A new builder with an 80x25 grid at scale 1 and no font yet (the default-font feature
supplies one at build time if none is set).
Sourcepub const fn scale(self, scale: u16) -> Self
pub const fn scale(self, scale: u16) -> Self
Sets the integer pixel scale (each glyph pixel becomes scalexscale physical pixels).
Sourcepub fn font(self, fonts: impl Into<FontChain<'static>>) -> Self
pub fn font(self, fonts: impl Into<FontChain<'static>>) -> Self
Sets the fonts glyphs are resolved through, overriding the default-font embedded font.
Takes either a single BitmapFont or a whole
FontChain, since a lone font is a chain of one. A chain is how a grid draws characters
CP437 has no mapping for (quadrants, sextants, braille): the extra coverage comes from a
fallback font built with
BitmapFont::with_charset, every font
in the chain is packed into the same glyph atlas, and the glyph is drawn from that atlas,
so it takes the cell’s foreground color like any other glyph (unlike a tileset sprite,
which carries its own colors).
Every font in a chain must agree on its glyph size, since that is the grid’s cell size, and
the chain’s glyphs must fit the atlas’s 16-bit slot space; otherwise
build fails.
§Examples
use retroglyph_gl::GlBackendBuilder;
use retroglyph_window::font::{BitmapFont, FontChain, unscii16};
// A fallback font declaring the quadrant glyphs CP437 has no mapping for.
static QUADRANTS: [u8; 3 * 16] = [0; 3 * 16];
const CHARSET: [(char, u8); 3] = [('▘', 0), ('▝', 1), ('▖', 2)];
static FALLBACKS: [BitmapFont; 1] =
[BitmapFont::with_charset(&QUADRANTS, 8, 16, 3, &CHARSET)];
let renderer = GlBackendBuilder::new()
.font(FontChain::new(unscii16::FONT, &FALLBACKS))
.build()
.expect("gl backend init failed");Sourcepub fn tileset(self, opts: TilesetOptions) -> Self
pub fn tileset(self, opts: TilesetOptions) -> Self
Registers a PNG sprite tileset (issue #366). Glyphs a tileset maps override the bitmap font
for those codepoints; register multiple and later ones win on codepoint collision. Build
the options with TilesetOptions::builder.
Available only with the tilesets feature.
Sourcepub fn build(self) -> Result<GlRenderer, GlBackendError>
pub fn build(self) -> Result<GlRenderer, GlBackendError>
Builds the GlRenderer.
The renderer holds no GL context yet; the context is created when the windowing loop calls
Presenter::init_surface.
§Errors
Returns GlBackendError::NoFont if no font was set and the default-font feature is
disabled, GlBackendError::MixedGlyphSizes if the configured chain’s fonts disagree on
their glyph size, GlBackendError::FontChainTooLarge if the chain’s glyphs overflow the
atlas’s slot space, GlBackendError::ZeroScale if scale is 0,
GlBackendError::ZeroGrid if either grid dimension is 0, or
GlBackendError::SurfaceTooLarge if cols/rows/scale combine to a surface wider or
taller than u32::MAX physical pixels.
Trait Implementations§
Source§impl Clone for GlBackendBuilder
impl Clone for GlBackendBuilder
Source§fn clone(&self) -> GlBackendBuilder
fn clone(&self) -> GlBackendBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GlBackendBuilder
impl Debug for GlBackendBuilder
Auto Trait Implementations§
impl Freeze for GlBackendBuilder
impl RefUnwindSafe for GlBackendBuilder
impl Send for GlBackendBuilder
impl Sync for GlBackendBuilder
impl Unpin for GlBackendBuilder
impl UnsafeUnpin for GlBackendBuilder
impl UnwindSafe for GlBackendBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.