Skip to content
Antonio Caggiano edited this page Oct 6, 2020 · 1 revision

These are the steps to use the library in order to start clearing the screen with some colors.

  1. Create a new display:
let display = Display::new().expect("Failed creating display");
  1. Create a new context:
let attr = ContextAttributes {
    major: 3,
    minor: 2,
    red_bits: 8,
    green_bits: 8,
    blue_bits: 8,
    alpha_bits: 8,
    depth_bits: 24,
    stencil_bits: 0,
};

let context = Context::new(&display, 480, 320, &attr).expect("Failed creating context");
context.make_current();
  1. Create a presenter:
let presenter = Presenter::new(&display, drm_sys::fourcc::DRM_FORMAT_RGB565, 0xFF080808)
    .expect("Failed creating presenter");
  1. In order to use gl calls, you need to load its symbols through EGL:
unsafe {
    gl::load_with(|symbol| {
        eglGetProcAddress(CString::new(symbol).unwrap().as_ptr()) as *const _
    });
};
  1. Now you can draw something:
unsafe {
    gl::ClearColor(0.9, 0.5, 1.0, 0.0);
    gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
}
  1. Once finished with drawing, we need to swap buffers and present the surface to the screen:
context.swap_buffers();

let surface = context.surface_lock();
presenter.post(surface, 0, 0, 480, 320, 0, 0, 320, 480, 3);
context.surface_unlock(surface);

That's all! 🤓

Clone this wiki locally