Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bevyengine
GitHub Repository: bevyengine/bevy
Path: blob/main/examples/window/transparent_window.rs
6595 views
1
//! Shows how to display a window in transparent mode.
2
//!
3
//! This feature works as expected depending on the platform. Please check the
4
//! [documentation](https://docs.rs/bevy/latest/bevy/prelude/struct.Window.html#structfield.transparent)
5
//! for more details.
6
7
use bevy::prelude::*;
8
#[cfg(any(target_os = "macos", target_os = "linux"))]
9
use bevy::window::CompositeAlphaMode;
10
11
fn main() {
12
App::new()
13
.add_plugins(DefaultPlugins.set(WindowPlugin {
14
primary_window: Some(Window {
15
// Setting `transparent` allows the `ClearColor`'s alpha value to take effect
16
transparent: true,
17
// Disabling window decorations to make it feel more like a widget than a window
18
decorations: false,
19
#[cfg(target_os = "macos")]
20
composite_alpha_mode: CompositeAlphaMode::PostMultiplied,
21
#[cfg(target_os = "linux")]
22
composite_alpha_mode: CompositeAlphaMode::PreMultiplied,
23
..default()
24
}),
25
..default()
26
}))
27
// ClearColor must have 0 alpha, otherwise some color will bleed through
28
.insert_resource(ClearColor(Color::NONE))
29
.add_systems(Startup, setup)
30
.run();
31
}
32
33
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
34
commands.spawn(Camera2d);
35
commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
36
}
37
38