PistonDevelopers / gfx_graphics

A Gfx 2D back-end for the Piston game engine
MIT License
55 stars 31 forks source link

Can't treat gfx_graphics as Graphics #344

Closed storyfeet closed 6 years ago

storyfeet commented 6 years ago

Hi I have functions that take a Parameter,

 pub fn draw<G:Graphics>(&self,c:Context,g:&mut G){
     //...
}

But when I try to invoke them

        window.draw_2d(&e,|c,mut g|{
            p_wind::clear([1.0,0.5,0.5,1.0],g);
            board.draw(c,&mut g)

        });

I get the following error

          board.draw(c,&mut g)
   |                   ^^^^ the trait `p_wind::Graphics` is not implemented for `&mut gfx_graphics::back_end::GfxGraphics<'_, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>`
   |
   = help: the following implementations were found:
             <gfx_graphics::back_end::GfxGraphics<'a, R, C> as p_wind::Graphics>

What's going on here?

should backend be private, as that seems to be where the impl is?

bvssvni commented 6 years ago

Probably wrong version number in Cargo.toml. Check dependencies on crates.io.

storyfeet commented 6 years ago

what vnum should I be using?

bvssvni commented 6 years ago

It depends on the version of piston2d-graphics. The version that piston2d-gfx_graphics uses should match with the piston2d-graphics version you use in your application code.

If you are in doubt, then use the latest version of each library. We use a tool called "Eco" to make sure that crates are published in a way such that latest versions work with each other.

storyfeet commented 6 years ago

I'm only etern crate-ing the piston_window , I've tried updating the version, and I get an error compiling one of it's dependencies.

error[E0507]: cannot move out of captured outer variable in an FnOnce closure --> /home/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/rusttype-0.4.3/src/lib.rs:314:54 | 314 | .and_then(|offset| tt::FontInfo::new(self.0, offset as usize)) | ^^^^ cannot move out of captured outer variable in an FnOnce closure

error: aborting due to previous error

error: Could not compile rusttype.

storyfeet commented 6 years ago

solved:

didn't need the mut in

board.draw(c,&mut g);