Iced: Transparency doesnt work with wgpu backend

Created on 5 Nov 2020  路  2Comments  路  Source: hecrj/iced

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" ]

screenshot-2020-11-05-T17-06-13-0100

  • features = ["glow", "glow_default_system_font", "debug", "palette" ]

screenshot-2020-11-05-T17-05-54-0100

bug

Most helpful comment

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" }

All 2 comments

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
+    }
+

image

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"

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michael-hart picture michael-hart  路  4Comments

aentity picture aentity  路  3Comments

Newbytee picture Newbytee  路  4Comments

casperstorm picture casperstorm  路  3Comments

Plecra picture Plecra  路  4Comments