gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 549 forks source link

Transparent window on wayland and glutin #1217

Open SiebenCorgie opened 7 years ago

SiebenCorgie commented 7 years ago

Hi, I tried to follow this tutorial. However, every time I try to create a window with glutin I get a dark rectangle (probably the window frame) but the inside should be filled I guess. gh_1

And this is how the cube example looks like: screenshot from 2017-04-01 15-17-27

I am on Wayland 1.13.0 with and intel/nvidia hybrid. I tried to run everything with "primusrun". But it didn't change anything.

This is the code I am using:

#[macro_use]
extern crate gfx;
extern crate gfx_window_glutin;
extern crate glutin;

use gfx::Device;

pub type ColorFormat = gfx::format::Rgba8;
pub type DepthFormat = gfx::format::DepthStencil;

pub fn main() {
    let builder = glutin::WindowBuilder::new()
        .with_title("Triangle example".to_string())
        .with_dimensions(1024, 768)
        .with_vsync();
    let (window, mut device, mut factory, main_color, mut main_depth) =
        gfx_window_glutin::init::<ColorFormat, DepthFormat>(builder);
    'main: loop {
        for event in window.poll_events() {
            match event {
                glutin::Event::KeyboardInput(_, _, Some(glutin::VirtualKeyCode::Escape)) |
                glutin::Event::Closed => break 'main,
                _ => {}
            }
        }
        window.swap_buffers().unwrap();
        device.cleanup();
    }
}

And this is the Cargo.toml:

name = "gfx_sdl_test"
version = "0.1.0"
authors = ["Siebencorgie"]

[dependencies]
gfx = "0.14"
glutin = "0.7"
gfx_window_glutin = "0.14"

Any idea what the problem could be? If you need more information about hard- or software, let me know.

msiglreith commented 7 years ago

Interesting! Seems like the compositor takes the alpha values of our framebuffers into account. In our cube example, the alpha values are incorrect (0.0f), resulting into a blending with the background.

Not sure if it should be transparent by default, this might be a glutin issue. I can reproduce it on windows by enabling transparency in the WindowBuilder.

SiebenCorgie commented 7 years ago

Interesting indeed. I tested the shadow example. Its working as it should. However, the window is still incomplete. It got missing close/minimize/maximize buttons, and not the correct, themed window frame.

Binero commented 7 years ago

I have this issue too on Wayland, but not Xorg. (Both Mutter)

mitchmindtree commented 7 years ago

I've also run into this on wayland+mutter, but via glium instead. This is probably either a glutin, winit, wayland-window or mutter issue. @vberger any ideas what might be going on?

elinorbgr commented 7 years ago

Not sure if it should be transparent by default, this might be a glutin issue.

I'm pretty sure it is a perfectly normal wayland behavior, given there doesn't exist any way to specify to the compositor that your window should not be transparent.

It got missing close/minimize/maximize buttons, and not the correct, themed window frame.

Wayland (or at least mutter) require client-side decorations to be drawn. Currently, winit draws them using wayland-window which is a very basic decorations implementation and is still WIP. Hence the missing buttons and ugly borders.

However, matching the compositor style would basically require either creating the window using GTK or parsing the GTK theme configuration and mimicking the rendering of it in wayland-window, which is way out of scope for this small crate.

OvermindDL1 commented 7 years ago

However, matching the compositor style would basically require either creating the window using GTK or parsing the GTK theme configuration and mimicking the rendering of it in wayland-window, which is way out of scope for this small crate.

As well as many of us prefer Qt as well.

torkleyy commented 5 years ago

What I get on Wayland looks a lot worse:

screenshot from 2018-10-01 17-20-58

(cube example of pre-ll)