[English]

OpenGL ES Display/Inputs driver(OpenGL ES 显示/输入驱动程序)

Overview(概述)

显示原文
The OpenGL ES display/input driver offers support for simulating the LVGL display and keyboard/mouse inputs in an desktop window created via GLFW.
It is an alternative to Wayland, XCB, SDL or Qt.

The main purpose for this driver is for testing/debugging the LVGL application in an OpenGL simulation window.


OpenGL ES 显示/输入 驱动程序 <https://github.com/lvgl/lvgl/src/drivers/opengles>__ 为通过GLFW创建的桌面窗口中的LVGL显示和键盘/鼠标输入提供模拟支持。
它是 Wayland、XCB、SDL 或 Qt 的替代方案。

这个驱动程序的主要目的是在 OpenGL 模拟窗口中测试/调试LVGL应用程序。

Prerequisites(先决条件)

显示原文

The OpenGL driver uses GLEW GLFW to access the OpenGL window manager.

  1. Install GLEW and GLFW: sudo apt-get install libglew-dev libglfw3-dev


OpenGL驱动程序使用GLEW GLFW来访问OpenGL窗口管理器。

  1. 安装GLEW和GLFW: sudo apt-get install libglew-dev libglfw3-dev

Configure OpenGL driver(配置OpenGL驱动程序)

显示原文
  1. Required linked libraries: -lGL -lGLEW -lglfw

  2. Enable the OpenGL driver support in lv_conf.h, by cmake compiler define or by KConfig
    #define LV_USE_OPENGLES  1
    

  1. 需要链接的库:-lGL -lGLEW -lglfw

  2. 在 lv_conf.h 中通过cmake编译器定义或KConfig启用OpenGL驱动程序支持
    #define LV_USE_OPENGLES  1
    

Basic usage(基本用法)

#include "lvgl/lvgl.h"
#include "lvgl/examples/lv_examples.h"
#include "lvgl/demos/lv_demos.h"

#define WIDTH 640
#define HEIGHT 480

int main()
{
    /* initialize lvgl */
    lv_init();

    /* create a window and initialize OpenGL */
    lv_glfw_window_t * window = lv_glfw_window_create(WIDTH, HEIGHT, true);
    /* create a display that flushes to a texture */
    lv_display_t * texture = lv_opengles_texture_create(WIDTH, HEIGHT);
    lv_display_set_default(texture);

    /* add the texture to the window */
    unsigned int texture_id = lv_opengles_texture_get_texture_id(texture);
    lv_glfw_texture_t * window_texture = lv_glfw_window_add_texture(window, texture_id, WIDTH, HEIGHT);

    /* get the mouse indev of the window texture */
    lv_indev_t * mouse = lv_glfw_texture_get_mouse_indev(window_texture);

    /* add a cursor to the mouse indev */
    LV_IMAGE_DECLARE(mouse_cursor_icon);
    lv_obj_t * cursor_obj = lv_image_create(lv_screen_active());
    lv_image_set_src(cursor_obj, &mouse_cursor_icon);
    lv_indev_set_cursor(mouse, cursor_obj);

    /* create objects on the screen */
    lv_demo_widgets();

    while (1)
    {
        uint32_t time_until_next = lv_timer_handler();
        lv_delay_ms(time_until_next);
    }

    return 0;
}

Advanced usage(高级用法)

OpenGL 驱动程序能够从用户那里绘制纹理。可以使用第三方库向纹理添加内容,然后驱动程序将在窗口中绘制该纹理。