Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency not working #567

Open
GeneralBombe opened this issue May 5, 2024 · 1 comment
Open

Transparency not working #567

GeneralBombe opened this issue May 5, 2024 · 1 comment

Comments

@GeneralBombe
Copy link

Hmmm, does anyone have a clue why my background is not being transparent?

extern crate glfw;
use glfw::{Action, Context, Key, WindowHint};
use glow::*;

fn main() {
    let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
    // Enable alpha channel for the window
    glfw.window_hint(WindowHint::TransparentFramebuffer(true));
    glfw.window_hint(WindowHint::Maximized(false));
    glfw.window_hint(WindowHint::ContextVersionMajor(3));
    glfw.window_hint(WindowHint::ContextVersionMinor(3));
    glfw.window_hint(WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core));
    
    

    let (mut window, events) = glfw.with_primary_monitor(|glfw, m| {
        glfw.create_window(200, 200, "Window",
            m.map_or(glfw::WindowMode::Windowed, |m| glfw::WindowMode::Windowed))
    }).expect("Failed to create GLFW window");

    window.set_key_polling(true);
    window.make_current();
    let gl = unsafe {
        glow::Context::from_loader_function(|s| window.get_proc_address(s) as *const _)
    };
    
    while !window.should_close() {
        unsafe { 
            gl.enable(glow::BLEND);
            gl.clear_color(0.0, 0.0, 0.0, 0.0);
            
            gl.clear(glow::COLOR_BUFFER_BIT);
        }
        
        glfw.poll_events();
        
        for (_, event) in glfw::flush_messages(&events) {
            handle_window_event(&mut window, event);
        }
        
        window.swap_buffers();
    }
}

fn handle_window_event(window: &mut glfw::Window, event: glfw::WindowEvent) {
    match event {
        glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
            window.set_should_close(true)
        }
        _ => {}
    }
}

All other colors work, except transparency.
Would really appreciate any help.
gl.clear_color(1.0, 0.0, 0.0, 0.1) shows as complete red, without any transparency.

I am on windows. I tried the same code in c++, it does not work.
Does anyone have a idea what my issue could be?
Ty in advance :)

@GeneralBombe
Copy link
Author

Well i found out why transparency is not working. If i initialize the window on my second screen, transparency works. On my main one however, transparency renders as black. But still, this issue does not persist with this crate. Would still appreciate if anyone knows a workaround :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant