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

Example help needed on how to use 'glx' feature #942

Open
Naginipython opened this issue Oct 23, 2024 · 2 comments
Open

Example help needed on how to use 'glx' feature #942

Naginipython opened this issue Oct 23, 2024 · 2 comments

Comments

@Naginipython
Copy link

I'm struggling to understand how to use 'glx' in this crate. Looks really cool, I am just struggling to fully figure it out. How do I get the framebuffer properly? How do I set up GLX?

let (conn, screen_num) = x11rb::connect(None)?;
let screen = &conn.setup().roots[screen_num];
let win_id = conn.generate_id()?;
let ctx_id = conn.generate_id()?;
let colormap_id = conn.generate_id()?;

 // Choose framebuffer config. This is wrong?
let fb_configs = glx::get_fb_configs(&conn, screen.root)?.reply()?;
let fb_config = fb_configs.property_list[0];

// Create OpenGL context
glx::create_new_context(&conn, ctx_id, fb_config, screen.root, 0x8014, 0, true)?;
        
// Create colormap
conn.create_colormap(ColormapAlloc::NONE, colormap_id, screen.root, fb_config)?;

let win_aux = &CreateWindowAux::new()
     .background_pixel(screen.white_pixel)
     .event_mask(EventMask::KEY_PRESS)
     .colormap(colormap_id);
conn.create_window(
    COPY_DEPTH_FROM_PARENT,
    win_id,
    screen.root,
    0,
    0,
    width,
    height,
    0,
    WindowClass::INPUT_OUTPUT,
    fb_config,
    &win_aux,
)?;
conn.map_window(win_id)?;
conn.flush()?;
        
glx::make_context_current(&conn, 0, win_id, win_id, ctx_id)?.reply()?;

// What else to do?

'game: loop {
        if let event: Event = conn.wait_for_event().expect("Couldn't get event") {
            match event {
                Event::KeyPress(key) => {
                    match key.detail {
                        9 => break 'game, // Esc
                        _ => {}
                    }
                }
                _ => {}
            }
    }
}
@Naginipython Naginipython changed the title Examples on how to use 'glx' feature Example help on how to use 'glx' feature Oct 24, 2024
@Naginipython Naginipython changed the title Example help on how to use 'glx' feature Example help needed on how to use 'glx' feature Oct 24, 2024
@psychon
Copy link
Owner

psychon commented Oct 26, 2024

TL;DR: Do not try to use the X11 GLX protocol directly. Use GLX through mesa instead.

Sorry, but the short version is "you do not". I am not 100% sure, but I think you would need the GLX X11 extension if you are implementing GLX. So, e.g. mesa would need this to talk to the X11 server. You would then use "proper GLX" through mesa.

For example, here is a piece of code where mesa uses the GLX X11 extension through XCB: https://gitlab.freedesktop.org/mesa/mesa/-/blob/b7560fa0488a7a72ad0ffa1ad5ca3f7d11257739/src/glx/clientinfo.c#L160-195

Sadly, Google didn't give me anything more useful than this. I think that most of the GLX X11 extension is not even used anymore. The phrase "indirect GLX" comes to mind. Google found that on https://en.wikipedia.org/wiki/AIGLX but that does not really say anything helpful.

@yshui
Copy link

yshui commented Oct 29, 2024

I think that most of the GLX X11 extension is not even used anymore.

It's still used for GLX, i.e. creating an OpenGL context via glXCreateContext is done through the GLX extension. OTOH EGL doesn't use it at all.

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