Render into an lv_cangas using OpenGL


I am currently learning about graphics libraries as I approach my project to make LVGL run on other and/or new systems. However, since I am visually impaired, I usually shied away from learning things like OpenGL, Vulkan or the likes. This basically bites me back now…hard.

What MCU/Processor/Board and compiler are you using?

Any, really. This is really just and example and helps me to learn how it should technically work.

What LVGL version are you using?

Git master - just fooling around for now.

What do you want to achieve?

I would love to learn how to render OpenGL content into an lv_canvas by setting the buffer to the GL render target. But, since I might be working with some oddball graphics APIs, I just want to learn the basics using OpenGL for now. Then I can use that knowledge for future implementations.

What have you tried so far?

I have been reading the sokol_gfx.h API and read articles on LearningOpenGL as well as taking a look at the lv_canvas API.

Code to reproduce


Screenshot and/or video


To start with, I would suggest looking up how to get OpenGL to render a 16bpp or 32bpp bitmap image into a C array buffer. You would also need to configure LV_COLOR_DEPTH to match the OpenGL color depth.

Then, if the OpenGL color format matches the LVGL one, you can use an adaptation of lv_example_canvas_1:

    /* Size should be CANVAS_WIDTH * CANVAS_HEIGHT * (2 for 16bpp or 4 for 32bpp */

    lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL);
    lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);

CANVAS_WIDTH and CANVAS_HEIGHT are self-explanatory. cbuf is the array OpenGL would be rendering into.