Type mismatch: image rendering function expects opengl_graphics::Texture
alexispurslane opened this issue · 3 comments
I'm trying to draw a texture which I've loaded from a file, but when I borrow the code from piston-examples
, I get an error saying that the image
function, which in the example accepts a piston_window::G2dTexture
, is actually expecting an graphics::Graphics::Texture
. I don't know how to convert from one to the other, what the difference is, or why the image drawing function wants a different type. I'm using the OpenGL backend, if that helps. Here's the error:
type mismatch resolving `<opengl_graphics::GlGraphics as graphics::Graphics>::Texture == piston_window::Texture<gfx_device_gl::Resources>`
expected struct `opengl_graphics::Texture`, found struct `piston_window::Texture`
note: expected type `opengl_graphics::Texture`
found type `piston_window::Texture<gfx_device_gl::Resources>`
and here's the relevant portions of my code:
for t in tiles {
let assets = find_folder::Search::ParentsThenKids(3, 3)
.for_folder("Tiles/")
.unwrap();
let asset = assets.join(t.to_owned() + ".png");
let asset: G2dTexture = Texture::from_path(
&mut window.factory,
&asset,
Flip::None,
&TextureSettings::new(),
).unwrap();
game.texture_map.insert(t.to_owned(), asset);
}
and
pub fn display_terrain(
gl: &mut GlGraphics,
args: &RenderArgs,
(x, y): Point2D,
tile: G2dTexture,
) {
let (iso_x, iso_y) = twod_to_iso((x * 64, y * 64));
image(&tile, [[0.0;3];2], gl);
}
There is an intermediary function between the draw call and display_terrain
that wraps it in the appropriate self.gl.draw(args.viewport(), |c, g| { /* ... */ });
Any help would be appreciated! Thanks.
@ChristopherDumas Did you manage to solve this? I'm facing a similar issue.
Yeah, so these are the imports I use now:
use piston_window::{image, Context, G2d, G2dTexture};
Before, I was importing image
from graphics
directly iirc, or openGL. What I found out was that piston_window re-exports everything with its own wrappers to work correctly with their types. Just use what piston_window exports.