use bevy::prelude::*; use bevy_mod_imgui::prelude::*; #[derive(Resource)] struct ImguiState { demo_window_open: bool, } fn main() { let mut app = App::new(); app.insert_resource(ClearColor(Color::srgba(0.2, 0.2, 0.2, 1.0))) .insert_resource(ImguiState { demo_window_open: true, }) .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_plugins(bevy_mod_imgui::ImguiPlugin { ini_filename: Some("hello-world.ini".into()), font_oversample_h: 2, font_oversample_v: 2, ..default() }) .add_systems(PostUpdate, imgui_example_ui); app.run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // plane commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)), material: materials.add(Color::srgb(0.3, 0.5, 0.3)), ..default() }); // cube commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::default().mesh()), material: materials.add(Color::srgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); // light commands.spawn(PointLightBundle { point_light: PointLight { shadows_enabled: true, ..default() }, transform: Transform::from_xyz(4.0, 8.0, 4.0), ..default() }); // camera commands.spawn(Camera3dBundle { transform: Transform::from_xyz(1.7, 1.7, 2.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y), tonemapping: bevy::core_pipeline::tonemapping::Tonemapping::None, ..default() }); } fn imgui_example_ui(mut context: NonSendMut, mut state: ResMut) { let ui = context.ui(); let window = ui.window("Hello world"); window .size([300.0, 100.0], imgui::Condition::FirstUseEver) .position([0.0, 0.0], imgui::Condition::FirstUseEver) .build(|| { ui.text("Hello world!"); ui.text("This...is...bevy_mod_imgui! (from PostUpdate)"); ui.separator(); let mouse_pos = ui.io().mouse_pos; ui.text(format!( "Mouse Position: ({:.1},{:.1})", mouse_pos[0], mouse_pos[1] )); }); if state.demo_window_open { ui.show_demo_window(&mut state.demo_window_open); } }