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

Trying to get Egui's Screenshot feature to work. #5741

Open
John-Nagle opened this issue Feb 22, 2025 · 1 comment
Open

Trying to get Egui's Screenshot feature to work. #5741

John-Nagle opened this issue Feb 22, 2025 · 1 comment

Comments

@John-Nagle
Copy link

Trying to get Egui's Screenshot feature to work.
Test program:

git clone https://github.com/John-Nagle/ui-mock.git 
cd ui-mock
git checkout screenshot
cargo build --examples
cd target/release/examples
./ui-mock

Select one of the dummy metaverse buttons, go through the dummy login (username and password do nothing), and get the 3D cube on screen. Use the Developer->Screenshot menu.

This executes


                        if ui
                            .button(t!("menu.developer.screenshot", state.get_lang()))
                            .clicked()
                        {
                            println!("Screenshot");
                            ui
                                .ctx()
                                .send_viewport_cmd(ViewportCommand::Screenshot(UserData::default()));
                        }

And "Screenshot" is printed.

On the event processing side, the code to look for a Screenshot event, in "screenshot.rs", is

pub fn check_for_screenshot(state: &CommonState) {
    let ctx = state.context.clone();
    let image = ctx.input(|i| {
        i.events
            .iter()
            .filter_map(|e| {
                println!("EGUI Event: {:?}", e); // ***TEMP***
                if let egui::Event::Screenshot { image, .. } = e {
                    Some(image.clone())
                } else {
                    None
                }
            })
            .last()
    });

    if let Some(image) = image {
        println!("Got screenshot.");
    }
}

This prints lots of other events, but no Screenshot event.

This code is modeled after the example at https://github.com/emilk/egui/blob/master/examples/screenshot/src/main.rs
What am I doing wrong?

Originally posted by @John-Nagle in #5740

@John-Nagle
Copy link
Author

This is on the graphics stack Rend3->Egui->Wgpu->Vulkan->Ubuntu Linux 22.04 LTS->NVidia 3070.

Looking at how Screenshot works, this request is passed down several levels until it finally gets processed at

https://github.com/emilk/egui/blob/master/crates/egui-wgpu/src/winit.rs#L357

and the actual communication with Wgpu is here:

https://github.com/emilk/egui/blob/master/crates/egui-wgpu/src/capture.rs#L13

so screenshot support for this stack seems to be present.

I'm not too sure about the path by which the screenshot result is returned. Searching through the list of Egui events to find it seems like a test-only approach. Maybe I'm searching that list at the wrong point in the frame cycle.

Whatever normally processes and consumes those events probably ought to make a callback to the user.

Big question: does this capture the whole window, or just the Egui overlay?

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