forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_windows.rs
61 lines (55 loc) · 1.64 KB
/
multiple_windows.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Uses two windows to visualize a 3D model from different angles.
use bevy::{
prelude::*,
render::camera::RenderTarget,
window::{CreateWindow, PresentMode, WindowId},
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(bevy::window::close_on_esc)
.run();
}
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut create_window_events: EventWriter<CreateWindow>,
) {
// add entities to the world
commands.spawn(SceneBundle {
scene: asset_server.load("models/monkey/Monkey.gltf#Scene0"),
..default()
});
// light
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 5.0, 4.0),
..default()
});
// main camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
let window_id = WindowId::new();
// sends out a "CreateWindow" event, which will be received by the windowing backend
create_window_events.send(CreateWindow {
id: window_id,
descriptor: WindowDescriptor {
width: 800.,
height: 600.,
present_mode: PresentMode::AutoNoVsync,
title: "Second window".to_string(),
..default()
},
});
// second window camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
camera: Camera {
target: RenderTarget::Window(window_id),
..default()
},
..default()
});
}