Open oknozor opened 4 years ago
See https://github.com/hecrj/iced/pull/371 / https://github.com/gfx-rs/wgpu/issues/687
tl;dr for now wgpu hardcodes opaque mode, so it needs to be patched. You can use my fork:
[patch.crates-io]
# patch: transparency (config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED)
wgpu-core = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
wgpu-types = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
See #371 / gfx-rs/wgpu#687
tl;dr for now wgpu hardcodes opaque mode, so it needs to be patched. You can use my fork:
[patch.crates-io] # patch: transparency (config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED) wgpu-core = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" } wgpu-types = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
I've followed this & used your fork, modified the examples, but the transparency still seems not working on macOS 11.0.1 Big Sur:
diff --git a/Cargo.toml b/Cargo.toml
index 6221ae4..6bbfb22 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -100,3 +100,8 @@ iced_web = { version = "0.3", path = "web" }
[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
features = ["image", "svg", "canvas"]
+
+[patch.crates-io]
+# patch: transparency (config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED)
+wgpu-core = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
+wgpu-types = { git = "https://github.com/myfreeweb/wgpu", branch = "v0.6-alpha" }
\ No newline at end of file
diff --git a/examples/clock/Cargo.toml b/examples/clock/Cargo.toml
index c6e3237..b2a819a 100644
--- a/examples/clock/Cargo.toml
+++ b/examples/clock/Cargo.toml
@@ -7,4 +7,4 @@ publish = false
[dependencies]
iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
-chrono = "0.4"
+chrono = "0.4"
\ No newline at end of file
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index b317ac0..3a52ff2 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,3 +1,5 @@
+
use iced::{
canvas::{self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke},
executor, time, Application, Color, Command, Container, Element, Length,
@@ -6,6 +8,11 @@ use iced::{
pub fn main() -> iced::Result {
Clock::run(Settings {
+ window: iced::window::Settings{
+ decorations: false,
+ transparent: true,
+ ..iced::window::Settings::default()
+ },
antialiasing: true,
..Settings::default()
})
@@ -32,7 +39,7 @@ impl Application for Clock {
now: chrono::Local::now(),
clock: Default::default(),
},
- Command::none(),
+ Command::none()
)
}
@@ -55,6 +62,10 @@ impl Application for Clock {
Command::none()
}
+ fn background_color(&self) -> Color {
+ Color::TRANSPARENT
+ }
+
But switching to glow works:
diff --git a/examples/clock/Cargo.toml b/examples/clock/Cargo.toml
index c6e3237..fce87f2 100644
--- a/examples/clock/Cargo.toml
+++ b/examples/clock/Cargo.toml
@@ -6,5 +6,5 @@ edition = "2018"
publish = false
[dependencies]
-iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
-chrono = "0.4"
+iced = { path = "../..", features = ["glow", "glow_canvas", "tokio", "debug"] }
+chrono = "0.4"
Is this still an issue in the latest versions of wgpu
?
Yes, you can see that https://github.com/gfx-rs/wgpu/issues/687 is still open. I still use a forked wgpu with a one-line patch for this.
I'm still having this same issue on macOS with the latest iced and wgpu, although it looks like wgpu merged that PR. Any advice on a fix / workaround?
Thanks!
Up! Same here
I believe I'm hitting this as well - here is a small sample project:
I've set application + children to have transparent background, but seeing a black box being rendered:
UPDATE(8/15): Rolled back to see if Iced 0.9.0
works - same issue.
UPDATE(8/16): I was able to avoid window transparency altogether by taking a different approach - project has been updated to use new approach, but updated the URL above as viable sample code that illustrates issue.
Just another data point, on my system transparency works for WGPU_BACKEND=gl
but not WGPU_BACKEND=vulkan
.
It seems the linked PR has been closed, so perhaps a fix can be merged ?
Seems transparency does not work on wgpu, is this normal ? I would happily use glow, but fonts are a bit aliased. Is there a workaround this ?
features = ["wgpu", "default_system_font", "debug", "palette" ]
features = ["glow", "glow_default_system_font", "debug", "palette" ]