deltaphc / raylib-rs

Rust bindings for raylib
Other
751 stars 134 forks source link

Is it possible to use this with `imgui-rs`? #168

Open MilowLab opened 1 year ago

MilowLab commented 1 year ago

Hello!

I have been trying to get this crate to work with imgui-rs. I can get a imgui-rs window up, but don't know how to link it with raylib. I'm assuming I need to access raylib's context for imgui to draw to. But I have not found a way to do that.

So I'm making a issue to try and see if its possible to hook the two together.

Thanks!

Sergiovan commented 7 months ago

Hello!

I have been trying to get this crate to work with imgui-rs. I can get a imgui-rs window up, but don't know how to link it with raylib. I'm assuming I need to access raylib's context for imgui to draw to. But I have not found a way to do that.

So I'm making a issue to try and see if its possible to hook the two together.

Thanks!

It is possible to hook imgui-rs and raylib-rs, I've made a gist from the code I use in my own project: https://gist.github.com/Sergiovan/8c6eaa8110440c31ff76f1d038ff4e9c I translated this from the C++ version of the raylib bindings, which are also referenced in the gist. To use them you simply

let (mut rl, thread) = raylib::init().size(1024, 768).title("Example").build();
let rl_imgui = imgui_raylib::RaylibImguiSupport::setup(&mut rl, &thread);

// And later
let ui = &mut rl_imgui.start_frame(&mut rl);
ui.window("blah") // etc

I can't promise the code is flawless and I'm fairly certain it does not cover the entire renderer/platform API, but I hope it can at least help you (or someone else reading this) with their own projects.

jestarray commented 6 months ago

I took this and made it work in my raylib game: https://github.com/michaelfairley/rust-imgui-opengl-renderer