I've got drawing text working when it's in the window draw closure, but when I move it to a function, I get a weird error that I can't seem to resolve. I've tried a few things, such as specify the generic type as noted in the error, but that large thing is also in error. I have use piston_window::*, so I'm not sure if something is missing. Code snippet below. Error is in the "text" function on .draw. Error message below that.
pub fn render(&mut self, window : &mut PistonWindow, event : &Event) {
window.draw_2d(event, |context, graphics| {
clear( [0.0, 0.0, 0.0, 1.0], graphics);
for c in &self.characters {
c.draw(&context, graphics);
}
let transform = context.transform.trans(100.0, 100.0);
Text::new_color([1.0, 1.0, 1.0, 1.0], 14)
.draw("Something", &mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
self.text("Something", 100.0, 100.0, &context, graphics);
});
}
fn text<G : Graphics>(&mut self, t : &str, x : f64, y : f64, context : &Context, graphics: &mut G){
let transform = context.transform.trans(x, y);
Text::new_color([1.0, 1.0, 1.0, 1.0], 14)
.draw(t,&mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
}
error[E0271]: type mismatch resolving <G as graphics::graphics::Graphics>::Texture == gfx_texture::Texture<gfx_device_gl::Resources>
--> src\game\mod.rs:111:14
|
111 | .draw(t,&mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
| ^^^^ expected associated type, found struct gfx_texture::Texture
|
= note: expected type <G as graphics::graphics::Graphics>::Texture
found type gfx_texture::Texture<gfx_device_gl::Resources>