Skip to content

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

@Naginipython

Description

@Naginipython

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
                        _ => {}
                    }
                }
                _ => {}
            }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions