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

(RaylibDrawHandle).draw_texture gives error [E0277] #142

Open
PerfectlyFineCode opened this issue Dec 4, 2022 · 0 comments
Open

(RaylibDrawHandle).draw_texture gives error [E0277] #142

PerfectlyFineCode opened this issue Dec 4, 2022 · 0 comments

Comments

@PerfectlyFineCode
Copy link

PerfectlyFineCode commented Dec 4, 2022

Library Version: 3.7.0
Rust version: 1.65.0
Toolchain: stable-x86-64-pc-windows-msvc

Description
I'm trying to load images from memory instead of loading them from a file.
But I've landed on an issue where the following function does not work because AsRef<Texture> is not implemented for Texture.
However. external C function DrawTexture works. Because it seems to be related to raylib_sys::Texture which is not convertible to raylib::ffi::Texture2D. Although I can definitely be wrong!

let img = LoadImageFromMemory(const_c!(".png"),
                              image_data.as_ptr() as *const _,
                              image_data.len() as i32);
let tex = LoadTextureFromImage(img) // Texture2D
d.draw_texture(tex, x as i32 - 128, y as i32, fade_out_color); // Gives error
error[E0277]: the trait bound `Texture: AsRef<Texture>` is not satisfied
   --> src\credits.rs:85:28
    |
85  |             d.draw_texture(tex, x as i32 - 128, y as i32, fade_out_color);
    |               ------------ ^^^ the trait `AsRef<Texture>` is not implemented for `Texture`
    |               |
    |               required by a bound introduced by this call
    |
note: required by a bound in `draw_texture`
   --> C:\Users\Nautilus\.cargo\registry\src\github.com-1ecc6299db9ec823\raylib-3.7.0\src\core\drawing.rs:849:23
    |
849 |         texture: impl AsRef<ffi::Texture2D>,
    |                       ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `draw_texture`

While this sample works

let img = LoadImageFromMemory(const_c!(".png"),
                              image_data.as_ptr() as *const _,
                              image_data.len() as i32);
let tex = LoadTextureFromImage(img) // Texture2D

DrawTexture(tex, x as i32 - 128, y as i32, raylib::ffi::Color {
     r: 255,
     g: 255,
     b: 255,
     a: 255,
});
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

1 participant