[RK3128-LINUX] 关于 OpenGL ES2 实现画图相关问题

2024-04-03 10:04

本文主要是介绍[RK3128-LINUX] 关于 OpenGL ES2 实现画图相关问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!


问题描述

在SDK中并没有找到有关OpenGL ES2 实现画图或者刷图的Demo程序,那么该功能如何实现呢?


解决方案:

标准api说明可以参考khronos定义:https://registry.khronos.org/

相关书籍:《OpenGL超级宝典》、《openGL编程指南》

demo源码可以到github上检索看看。在SDK工程中,下面的路径下有一个简单demo,可供参考。 {SDK_PATH}/buildroot/output/rockchip_{rk3326_64}/build/weston-3.0.0/clients/simple-egl.c
如下为simple-egl.c代码:

/** Copyright © 2011 Benjamin Franzke** Permission is hereby granted, free of charge, to any person obtaining a* copy of this software and associated documentation files (the "Software"),* to deal in the Software without restriction, including without limitation* the rights to use, copy, modify, merge, publish, distribute, sublicense,* and/or sell copies of the Software, and to permit persons to whom the* Software is furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice (including the next* paragraph) shall be included in all copies or substantial portions of the* Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER* DEALINGS IN THE SOFTWARE.*/
#include "config.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <assert.h>
#include <signal.h>
#include <linux/input.h>
#include <wayland-client.h>
#include <wayland-egl.h>
#include <wayland-cursor.h>
#include <GLES2/gl2.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "xdg-shell-unstable-v6-client-protocol.h"
#include <sys/types.h>
#include <unistd.h>
#include "ivi-application-client-protocol.h"
#define IVI_SURFACE_ID 9000
#include "shared/helpers.h"
#include "shared/platform.h"
#include "weston-egl-ext.h"
struct window;
struct seat;
struct display {struct wl_display *display;struct wl_registry *registry;struct wl_compositor *compositor;struct zxdg_shell_v6 *shell;struct wl_seat *seat;struct wl_pointer *pointer;struct wl_touch *touch;struct wl_keyboard *keyboard;struct wl_shm *shm;struct wl_cursor_theme *cursor_theme;struct wl_cursor *default_cursor;struct wl_surface *cursor_surface;struct {EGLDisplay dpy;EGLContext ctx;EGLConfig conf;} egl;struct window *window;struct ivi_application *ivi_application;PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC swap_buffers_with_damage;
};
struct geometry {int width, height;
};
struct window {struct display *display;struct geometry geometry, window_size;struct {GLuint rotation_uniform;GLuint pos;GLuint col;} gl;uint32_t benchmark_time, frames;struct wl_egl_window *native;struct wl_surface *surface;struct zxdg_surface_v6 *xdg_surface;struct zxdg_toplevel_v6 *xdg_toplevel;struct ivi_surface *ivi_surface;EGLSurface egl_surface;struct wl_callback *callback;int fullscreen, opaque, buffer_size, frame_sync, delay;bool wait_for_configure;
};
static const char *vert_shader_text ="uniform mat4 rotation;\n""attribute vec4 pos;\n""attribute vec4 color;\n""varying vec4 v_color;\n""void main() {\n""  gl_Position = rotation * pos;\n""  v_color = color;\n""}\n";
static const char *frag_shader_text ="precision mediump float;\n""varying vec4 v_color;\n""void main() {\n""  gl_FragColor = v_color;\n""}\n";
static int running = 1;
static void
init_egl(struct display *display, struct window *window)
{static const struct {char *extension, *entrypoint;} swap_damage_ext_to_entrypoint[] = {{.extension = "EGL_EXT_swap_buffers_with_damage",.entrypoint = "eglSwapBuffersWithDamageEXT",},{.extension = "EGL_KHR_swap_buffers_with_damage",.entrypoint = "eglSwapBuffersWithDamageKHR",},};static const EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2,EGL_NONE};const char *extensions;EGLint config_attribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT,EGL_RED_SIZE, 1,EGL_GREEN_SIZE, 1,EGL_BLUE_SIZE, 1,EGL_ALPHA_SIZE, 1,EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,EGL_NONE};EGLint major, minor, n, count, i, size;EGLConfig *configs;EGLBoolean ret;if (window->opaque || window->buffer_size == 16)config_attribs[9] = 0;display->egl.dpy =weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR,display->display, NULL);assert(display->egl.dpy);ret = eglInitialize(display->egl.dpy, &major, &minor);assert(ret == EGL_TRUE);ret = eglBindAPI(EGL_OPENGL_ES_API);assert(ret == EGL_TRUE);if (!eglGetConfigs(display->egl.dpy, NULL, 0, &count) || count < 1)assert(0);configs = calloc(count, sizeof *configs);assert(configs);ret = eglChooseConfig(display->egl.dpy, config_attribs,configs, count, &n);assert(ret && n >= 1);for (i = 0; i < n; i++) {eglGetConfigAttrib(display->egl.dpy,configs[i], EGL_BUFFER_SIZE, &size);if (window->buffer_size == size) {display->egl.conf = configs[i];break;}}free(configs);if (display->egl.conf == NULL) {fprintf(stderr, "did not find config with buffer size %d\n",window->buffer_size);exit(EXIT_FAILURE);}display->egl.ctx = eglCreateContext(display->egl.dpy,display->egl.conf,EGL_NO_CONTEXT, context_attribs);assert(display->egl.ctx);display->swap_buffers_with_damage = NULL;extensions = eglQueryString(display->egl.dpy, EGL_EXTENSIONS);if (extensions &&weston_check_egl_extension(extensions, "EGL_EXT_buffer_age")) {for (i = 0; i < (int) ARRAY_LENGTH(swap_damage_ext_to_entrypoint); i++) {if (weston_check_egl_extension(extensions,swap_damage_ext_to_entrypoint[i].extension)) {/* The EXTPROC is identical to the KHR one */display->swap_buffers_with_damage =(PFNEGLSWAPBUFFERSWITHDAMAGEEXTPROC)eglGetProcAddress(swap_damage_ext_to_entrypoint[i].entrypoint);break;}}}if (display->swap_buffers_with_damage)printf("has EGL_EXT_buffer_age and %s\n", swap_damage_ext_to_entrypoint[i].extension);
}
static void
fini_egl(struct display *display)
{eglTerminate(display->egl.dpy);eglReleaseThread();
}
static GLuint
create_shader(struct window *window, const char *source, GLenum shader_type)
{GLuint shader;GLint status;shader = glCreateShader(shader_type);assert(shader != 0);glShaderSource(shader, 1, (const char **) &source, NULL);glCompileShader(shader);glGetShaderiv(shader, GL_COMPILE_STATUS, &status);if (!status) {char log[1000];GLsizei len;glGetShaderInfoLog(shader, 1000, &len, log);fprintf(stderr, "Error: compiling %s: %*s\n",shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",len, log);exit(1);}return shader;
}
static void
init_gl(struct window *window)
{GLuint frag, vert;GLuint program;GLint status;frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);program = glCreateProgram();glAttachShader(program, frag);glAttachShader(program, vert);glLinkProgram(program);glGetProgramiv(program, GL_LINK_STATUS, &status);if (!status) {char log[1000];GLsizei len;glGetProgramInfoLog(program, 1000, &len, log);fprintf(stderr, "Error: linking:\n%*s\n", len, log);exit(1);}glUseProgram(program);window->gl.pos = 0;window->gl.col = 1;glBindAttribLocation(program, window->gl.pos, "pos");glBindAttribLocation(program, window->gl.col, "color");glLinkProgram(program);window->gl.rotation_uniform =glGetUniformLocation(program, "rotation");
}
static void
handle_surface_configure(void *data, struct zxdg_surface_v6 *surface,uint32_t serial)
{struct window *window = data;zxdg_surface_v6_ack_configure(surface, serial);window->wait_for_configure = false;
}
static const struct zxdg_surface_v6_listener xdg_surface_listener = {handle_surface_configure
};
static void
handle_toplevel_configure(void *data, struct zxdg_toplevel_v6 *toplevel,int32_t width, int32_t height,struct wl_array *states)
{struct window *window = data;uint32_t *p;window->fullscreen = 0;wl_array_for_each(p, states) {uint32_t state = *p;switch (state) {case ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN:window->fullscreen = 1;break;}}if (width > 0 && height > 0) {if (!window->fullscreen) {window->window_size.width = width;window->window_size.height = height;}window->geometry.width = width;window->geometry.height = height;} else if (!window->fullscreen) {window->geometry = window->window_size;}if (window->native)wl_egl_window_resize(window->native,window->geometry.width,window->geometry.height, 0, 0);
}
static void
handle_toplevel_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
{running = 0;
}
static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {handle_toplevel_configure,handle_toplevel_close,
};
static void
handle_ivi_surface_configure(void *data, struct ivi_surface *ivi_surface,int32_t width, int32_t height)
{struct window *window = data;wl_egl_window_resize(window->native, width, height, 0, 0);window->geometry.width = width;window->geometry.height = height;if (!window->fullscreen)window->window_size = window->geometry;
}
static const struct ivi_surface_listener ivi_surface_listener = {handle_ivi_surface_configure,
};
static void
create_xdg_surface(struct window *window, struct display *display)
{window->xdg_surface = zxdg_shell_v6_get_xdg_surface(display->shell,window->surface);zxdg_surface_v6_add_listener(window->xdg_surface,&xdg_surface_listener, window);window->xdg_toplevel =zxdg_surface_v6_get_toplevel(window->xdg_surface);zxdg_toplevel_v6_add_listener(window->xdg_toplevel,&xdg_toplevel_listener, window);zxdg_toplevel_v6_set_title(window->xdg_toplevel, "simple-egl");window->wait_for_configure = true;wl_surface_commit(window->surface);
}
static void
create_ivi_surface(struct window *window, struct display *display)
{uint32_t id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid();window->ivi_surface =ivi_application_surface_create(display->ivi_application,id_ivisurf, window->surface);if (window->ivi_surface == NULL) {fprintf(stderr, "Failed to create ivi_client_surface\n");abort();}ivi_surface_add_listener(window->ivi_surface,&ivi_surface_listener, window);
}
static void
create_surface(struct window *window)
{struct display *display = window->display;EGLBoolean ret;window->surface = wl_compositor_create_surface(display->compositor);window->native =wl_egl_window_create(window->surface,window->geometry.width,window->geometry.height);window->egl_surface =weston_platform_create_egl_surface(display->egl.dpy,display->egl.conf,window->native, NULL);if (display->shell) {create_xdg_surface(window, display);} else if (display->ivi_application ) {create_ivi_surface(window, display);} else {assert(0);}ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,window->egl_surface, window->display->egl.ctx);assert(ret == EGL_TRUE);if (!window->frame_sync)eglSwapInterval(display->egl.dpy, 0);if (!display->shell)return;if (window->fullscreen)zxdg_toplevel_v6_set_fullscreen(window->xdg_toplevel, NULL);
}
static void
destroy_surface(struct window *window)
{/* Required, otherwise segfault in egl_dri2.c: dri2_make_current()* on eglReleaseThread(). */eglMakeCurrent(window->display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,EGL_NO_CONTEXT);weston_platform_destroy_egl_surface(window->display->egl.dpy,window->egl_surface);wl_egl_window_destroy(window->native);if (window->xdg_toplevel)zxdg_toplevel_v6_destroy(window->xdg_toplevel);if (window->xdg_surface)zxdg_surface_v6_destroy(window->xdg_surface);if (window->display->ivi_application)ivi_surface_destroy(window->ivi_surface);wl_surface_destroy(window->surface);if (window->callback)wl_callback_destroy(window->callback);
}
static void
redraw(void *data, struct wl_callback *callback, uint32_t time)
{struct window *window = data;struct display *display = window->display;static const GLfloat verts[3][2] = {{ -0.5, -0.5 },{  0.5, -0.5 },{  0,    0.5 }};static const GLfloat colors[3][3] = {{ 1, 0, 0 },{ 0, 1, 0 },{ 0, 0, 1 }};GLfloat angle;GLfloat rotation[4][4] = {{ 1, 0, 0, 0 },{ 0, 1, 0, 0 },{ 0, 0, 1, 0 },{ 0, 0, 0, 1 }};static const uint32_t speed_div = 5, benchmark_interval = 5;struct wl_region *region;EGLint rect[4];EGLint buffer_age = 0;struct timeval tv;assert(window->callback == callback);window->callback = NULL;if (callback)wl_callback_destroy(callback);gettimeofday(&tv, NULL);time = tv.tv_sec * 1000 + tv.tv_usec / 1000;if (window->frames == 0)window->benchmark_time = time;if (time - window->benchmark_time > (benchmark_interval * 1000)) {printf("%d frames in %d seconds: %f fps\n",window->frames,benchmark_interval,(float) window->frames / benchmark_interval);window->benchmark_time = time;window->frames = 0;}angle = (time / speed_div) % 360 * M_PI / 180.0;rotation[0][0] =  cos(angle);rotation[0][2] =  sin(angle);rotation[2][0] = -sin(angle);rotation[2][2] =  cos(angle);if (display->swap_buffers_with_damage)eglQuerySurface(display->egl.dpy, window->egl_surface,EGL_BUFFER_AGE_EXT, &buffer_age);glViewport(0, 0, window->geometry.width, window->geometry.height);glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,(GLfloat *) rotation);glClearColor(0.0, 0.0, 0.0, 0.5);glClear(GL_COLOR_BUFFER_BIT);glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);glEnableVertexAttribArray(window->gl.pos);glEnableVertexAttribArray(window->gl.col);glDrawArrays(GL_TRIANGLES, 0, 3);glDisableVertexAttribArray(window->gl.pos);glDisableVertexAttribArray(window->gl.col);usleep(window->delay);if (window->opaque || window->fullscreen) {region = wl_compositor_create_region(window->display->compositor);wl_region_add(region, 0, 0,window->geometry.width,window->geometry.height);wl_surface_set_opaque_region(window->surface, region);wl_region_destroy(region);} else {wl_surface_set_opaque_region(window->surface, NULL);}if (display->swap_buffers_with_damage && buffer_age > 0) {rect[0] = window->geometry.width / 4 - 1;rect[1] = window->geometry.height / 4 - 1;rect[2] = window->geometry.width / 2 + 2;rect[3] = window->geometry.height / 2 + 2;display->swap_buffers_with_damage(display->egl.dpy,window->egl_surface,rect, 1);} else {eglSwapBuffers(display->egl.dpy, window->egl_surface);}window->frames++;
}
static void
pointer_handle_enter(void *data, struct wl_pointer *pointer,uint32_t serial, struct wl_surface *surface,wl_fixed_t sx, wl_fixed_t sy)
{struct display *display = data;struct wl_buffer *buffer;struct wl_cursor *cursor = display->default_cursor;struct wl_cursor_image *image;if (display->window->fullscreen)wl_pointer_set_cursor(pointer, serial, NULL, 0, 0);else if (cursor) {image = display->default_cursor->images[0];buffer = wl_cursor_image_get_buffer(image);if (!buffer)return;wl_pointer_set_cursor(pointer, serial,display->cursor_surface,image->hotspot_x,image->hotspot_y);wl_surface_attach(display->cursor_surface, buffer, 0, 0);wl_surface_damage(display->cursor_surface, 0, 0,image->width, image->height);wl_surface_commit(display->cursor_surface);}
}
static void
pointer_handle_leave(void *data, struct wl_pointer *pointer,uint32_t serial, struct wl_surface *surface)
{
}
static void
pointer_handle_motion(void *data, struct wl_pointer *pointer,uint32_t time, wl_fixed_t sx, wl_fixed_t sy)
{
}
static void
pointer_handle_button(void *data, struct wl_pointer *wl_pointer,uint32_t serial, uint32_t time, uint32_t button,uint32_t state)
{struct display *display = data;if (!display->window->xdg_toplevel)return;if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED)zxdg_toplevel_v6_move(display->window->xdg_toplevel,display->seat, serial);
}
static void
pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,uint32_t time, uint32_t axis, wl_fixed_t value)
{
}
static const struct wl_pointer_listener pointer_listener = {pointer_handle_enter,pointer_handle_leave,pointer_handle_motion,pointer_handle_button,pointer_handle_axis,
};
static void
touch_handle_down(void *data, struct wl_touch *wl_touch,uint32_t serial, uint32_t time, struct wl_surface *surface,int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
{struct display *d = (struct display *)data;if (!d->shell)return;zxdg_toplevel_v6_move(d->window->xdg_toplevel, d->seat, serial);
}
static void
touch_handle_up(void *data, struct wl_touch *wl_touch,uint32_t serial, uint32_t time, int32_t id)
{
}
static void
touch_handle_motion(void *data, struct wl_touch *wl_touch,uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
{
}
static void
touch_handle_frame(void *data, struct wl_touch *wl_touch)
{
}
static void
touch_handle_cancel(void *data, struct wl_touch *wl_touch)
{
}
static const struct wl_touch_listener touch_listener = {touch_handle_down,touch_handle_up,touch_handle_motion,touch_handle_frame,touch_handle_cancel,
};
static void
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,uint32_t format, int fd, uint32_t size)
{
}
static void
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,uint32_t serial, struct wl_surface *surface,struct wl_array *keys)
{
}
static void
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,uint32_t serial, struct wl_surface *surface)
{
}
static void
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,uint32_t serial, uint32_t time, uint32_t key,uint32_t state)
{struct display *d = data;if (!d->shell)return;if (key == KEY_F11 && state) {if (d->window->fullscreen)zxdg_toplevel_v6_unset_fullscreen(d->window->xdg_toplevel);elsezxdg_toplevel_v6_set_fullscreen(d->window->xdg_toplevel,NULL);} else if (key == KEY_ESC && state)running = 0;
}
static void
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,uint32_t serial, uint32_t mods_depressed,uint32_t mods_latched, uint32_t mods_locked,uint32_t group)
{
}
static const struct wl_keyboard_listener keyboard_listener = {keyboard_handle_keymap,keyboard_handle_enter,keyboard_handle_leave,keyboard_handle_key,keyboard_handle_modifiers,
};
static void
seat_handle_capabilities(void *data, struct wl_seat *seat,enum wl_seat_capability caps)
{struct display *d = data;if ((caps & WL_SEAT_CAPABILITY_POINTER) && !d->pointer) {d->pointer = wl_seat_get_pointer(seat);wl_pointer_add_listener(d->pointer, &pointer_listener, d);} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && d->pointer) {wl_pointer_destroy(d->pointer);d->pointer = NULL;}if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !d->keyboard) {d->keyboard = wl_seat_get_keyboard(seat);wl_keyboard_add_listener(d->keyboard, &keyboard_listener, d);} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && d->keyboard) {wl_keyboard_destroy(d->keyboard);d->keyboard = NULL;}if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !d->touch) {d->touch = wl_seat_get_touch(seat);wl_touch_set_user_data(d->touch, d);wl_touch_add_listener(d->touch, &touch_listener, d);} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && d->touch) {wl_touch_destroy(d->touch);d->touch = NULL;}
}
static const struct wl_seat_listener seat_listener = {seat_handle_capabilities,
};
static void
xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial)
{zxdg_shell_v6_pong(shell, serial);
}
static const struct zxdg_shell_v6_listener xdg_shell_listener = {xdg_shell_ping,
};
static void
registry_handle_global(void *data, struct wl_registry *registry,uint32_t name, const char *interface, uint32_t version)
{struct display *d = data;if (strcmp(interface, "wl_compositor") == 0) {d->compositor =wl_registry_bind(registry, name,&wl_compositor_interface,MIN(version, 4));} else if (strcmp(interface, "zxdg_shell_v6") == 0) {d->shell = wl_registry_bind(registry, name,&zxdg_shell_v6_interface, 1);zxdg_shell_v6_add_listener(d->shell, &xdg_shell_listener, d);} else if (strcmp(interface, "wl_seat") == 0) {d->seat = wl_registry_bind(registry, name,&wl_seat_interface, 1);wl_seat_add_listener(d->seat, &seat_listener, d);} else if (strcmp(interface, "wl_shm") == 0) {d->shm = wl_registry_bind(registry, name,&wl_shm_interface, 1);d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm);if (!d->cursor_theme) {fprintf(stderr, "unable to load default theme\n");return;}d->default_cursor =wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");if (!d->default_cursor) {fprintf(stderr, "unable to load default left pointer\n");// TODO: abort ?}} else if (strcmp(interface, "ivi_application") == 0) {d->ivi_application =wl_registry_bind(registry, name,&ivi_application_interface, 1);}
}
static void
registry_handle_global_remove(void *data, struct wl_registry *registry,uint32_t name)
{
}
static const struct wl_registry_listener registry_listener = {registry_handle_global,registry_handle_global_remove
};
static void
signal_int(int signum)
{running = 0;
}
static void
usage(int error_code)
{fprintf(stderr, "Usage: simple-egl [OPTIONS]\n\n""  -d <us>\tBuffer swap delay in microseconds\n""  -f\tRun in fullscreen mode\n""  -o\tCreate an opaque surface\n""  -s\tUse a 16 bpp EGL config\n""  -b\tDon't sync to compositor redraw (eglSwapInterval 0)\n""  -h\tThis help text\n\n");exit(error_code);
}
int
main(int argc, char **argv)
{struct sigaction sigint;struct display display = { 0 };struct window  window  = { 0 };int i, ret = 0;window.display = &display;display.window = &window;window.geometry.width  = 250;window.geometry.height = 250;window.window_size = window.geometry;window.buffer_size = 32;window.frame_sync = 1;window.delay = 0;for (i = 1; i < argc; i++) {if (strcmp("-d", argv[i]) == 0 && i+1 < argc)window.delay = atoi(argv[++i]);else if (strcmp("-f", argv[i]) == 0)window.fullscreen = 1;else if (strcmp("-o", argv[i]) == 0)window.opaque = 1;else if (strcmp("-s", argv[i]) == 0)window.buffer_size = 16;else if (strcmp("-b", argv[i]) == 0)window.frame_sync = 0;else if (strcmp("-h", argv[i]) == 0)usage(EXIT_SUCCESS);elseusage(EXIT_FAILURE);}display.display = wl_display_connect(NULL);assert(display.display);display.registry = wl_display_get_registry(display.display);wl_registry_add_listener(display.registry,&registry_listener, &display);wl_display_roundtrip(display.display);init_egl(&display, &window);create_surface(&window);init_gl(&window);display.cursor_surface =wl_compositor_create_surface(display.compositor);sigint.sa_handler = signal_int;sigemptyset(&sigint.sa_mask);sigint.sa_flags = SA_RESETHAND;sigaction(SIGINT, &sigint, NULL);/* The mainloop here is a little subtle.  Redrawing will cause* EGL to read events so we can just call* wl_display_dispatch_pending() to handle any events that got* queued up as a side effect. */while (running && ret != -1) {if (window.wait_for_configure) {wl_display_dispatch(display.display);} else {wl_display_dispatch_pending(display.display);redraw(&window, NULL, 0);}}fprintf(stderr, "simple-egl exiting\n");destroy_surface(&window);fini_egl(&display);wl_surface_destroy(display.cursor_surface);if (display.cursor_theme)wl_cursor_theme_destroy(display.cursor_theme);if (display.shell)zxdg_shell_v6_destroy(display.shell);if (display.ivi_application)ivi_application_destroy(display.ivi_application);if (display.compositor)wl_compositor_destroy(display.compositor);wl_registry_destroy(display.registry);wl_display_flush(display.display);wl_display_disconnect(display.display);return 0;
}

这篇关于[RK3128-LINUX] 关于 OpenGL ES2 实现画图相关问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/872605

相关文章

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

好题——hdu2522(小数问题:求1/n的第一个循环节)

好喜欢这题,第一次做小数问题,一开始真心没思路,然后参考了网上的一些资料。 知识点***********************************无限不循环小数即无理数,不能写作两整数之比*****************************(一开始没想到,小学没学好) 此题1/n肯定是一个有限循环小数,了解这些后就能做此题了。 按照除法的机制,用一个函数表示出来就可以了,代码如下

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

sqlite3 相关知识

WAL 模式 VS 回滚模式 特性WAL 模式回滚模式(Rollback Journal)定义使用写前日志来记录变更。使用回滚日志来记录事务的所有修改。特点更高的并发性和性能;支持多读者和单写者。支持安全的事务回滚,但并发性较低。性能写入性能更好,尤其是读多写少的场景。写操作会造成较大的性能开销,尤其是在事务开始时。写入流程数据首先写入 WAL 文件,然后才从 WAL 刷新到主数据库。数据在开始

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal