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

Getting an Instance of Graphics2D without Window #75

Open
johannes-adr opened this issue Mar 2, 2023 · 2 comments
Open

Getting an Instance of Graphics2D without Window #75

johannes-adr opened this issue Mar 2, 2023 · 2 comments

Comments

@johannes-adr
Copy link

johannes-adr commented Mar 2, 2023

Hello people,

I need a way to get a Graphics2D object without windows for my application. I want to further process the image buffer itself using the built-in caputer function. Is this possible? If yes, how would it work?

    let mut renderer: GLRenderer = todo!();
    renderer.draw_frame(|graphics| {
        graphics.clear_screen(Color::WHITE);
        graphics.draw_circle((100.0, 100.0), 75.0, Color::BLUE);
        let img = graphics.capture(image::ImageDataType::RGB);
        // ...
    });

To be precise with my needs, i want to implement a hardware accelerated drawing backend for my plotting library. It should draw (with help of this library) and save the result to a bitmap file.

@QuantumBadger
Copy link
Owner

Thanks for the question! Here's an example from the test framework using Glutin on Linux:

    let context_builder = glutin::ContextBuilder::new()
        .with_gl_debug_flag(true)
        .with_multisampling(0)
        .with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (2, 0)));

   let context = context_builder
        .with_vsync(false)
        .build_headless(&event_loop, PhysicalSize::new(width, height))
        .unwrap();

    let context = unsafe { context.make_current().unwrap() };

    let mut renderer = unsafe {
        GLRenderer::new_for_gl_context((width, height), |name| {
            context.get_proc_address(name) as *const _
        })
        .unwrap()
    };

I think this only works on Linux, so you may need to use something other than build_headless on Mac and Windows.

@bambooCZ
Copy link

bambooCZ commented Nov 30, 2024

@QuantumBadger I don't want to be rude but If your snippet was supposed to work on linux then it isn't working. Mainly because glutin::ContextBuilder doesn't exist.

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

3 participants