1

I am currently working on a project in Rust with the piston game engine (Using piston_window version 0.123.0) and I am having an issue with rendering text. The draw function returns an error fro a non implemented trait.

Here is the code:

// Get font for text rendering
let font = include_bytes!("font\\UbuntuMono-B.ttf");
let glyphs = Glyphs::from_bytes(font,
    window.create_texture_context(),
    TextureSettings::new())
    .unwrap();

Which is passed through a function:

Draw::render(&mut window, &event,
             &game.matrix,
             &game.frame_counter,
             &mut glyphs)

To this function:

pub fn render(window: &mut PistonWindow,
              event: &Event, matrix: &Matrix,
              frame: &i32, glyphs: &mut Glyphs)
{
    // Stuff
}

Where the text rendering occours:

Text::new_color(WHITE, 12).draw( // The draw() here is highlighted red for the error
     "Hold",
     &mut glyphs,
     &context.draw_state,
     context.transform
          .trans(184.0, 38.0),
     graphics
)

And returns the error message:

the trait bound `&mut piston_window::glyph_cache::rusttype::GlyphCache<'static, piston_window::TextureContext<gfx_device_gl::factory::Factory, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>, piston_window::Texture<gfx_device_gl::Resources>>: piston_window::CharacterCache` is not satisfied

the trait `piston_window::CharacterCache` is not implemented for `&mut piston_window::glyph_cache::rusttype::GlyphCache<'static, piston_window::TextureContext<gfx_device_gl::factory::Factory, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>, piston_window::Texture<gfx_device_gl::Resources>>`

help: the following implementations were found:
        <piston_window::glyph_cache::rusttype::GlyphCache<'b, F, T> as piston_window::CharacterCache>

Any help with how to fix this error would be appreciated. I apologise if I have given too much/little or incorrect info for this issue, I am not too familiar with StackOverflow.

Krone
  • 23
  • 3

0 Answers0