Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch: image rendering function expects opengl_graphics::Texture #232

Open
alexispurslane opened this issue Aug 13, 2018 · 3 comments

Comments

@alexispurslane
Copy link

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.

@srishanbhattarai
Copy link

@ChristopherDumas Did you manage to solve this? I'm facing a similar issue.

@alexispurslane
Copy link
Author

alexispurslane commented Dec 29, 2018 via email

@alexispurslane
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants