In my game I need to render some in-game textures into UI (I'm using ggez 0.8.1 and imgui 0.8.0). As ggez 0.8.1 uses wgpu for rendering I need to use wgpu backend for imgui. So there's my question: how can I render imgui's DrawData
inside ggez's draw
function?
I've tried this code but it's not showing me UI (the other game things are working).
let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::BLACK);
let ui = self.imgui.frame();
imgui::Window::new("")
.size([200.0, 100.0], imgui::Condition::Always)
.position([0.0, 0.0], imgui::Condition::Always)
.flags(imgui::WindowFlags::NO_RESIZE | imgui::WindowFlags::NO_COLLAPSE)
.build(&ui, || {
ui.text(format!("tick id: {}", self.tick_id));
});
let draw_data = ui.render();
unsafe {
let encoder = ctx.gfx.commands().unwrap() as *mut CommandEncoder;
let mut pass = (&mut *encoder).begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("UI RenderPass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &ctx.gfx.frame().wgpu().1,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
store: true,
},
})],
depth_stencil_attachment: None,
});
let wgpu_ctx = ctx.gfx.wgpu();
self.renderer
.render(&draw_data, &wgpu_ctx.queue, &wgpu_ctx.device, &mut pass)
.unwrap();
};
canvas.finish(ctx)?;