wayland(xdg_wm_base) + egl + opengles 纹理贴图进阶实例(四)

文章目录

  • 前言
  • 一、使用gstreamer 获取 pattern 图片
  • 二、代码实例
    • 1. pattern 图片作为纹理数据源的代码实例
      • 1.1 基于opengles2.0 接口的 egl_wayland_texture2_1.c
      • 1.2 基于opengles3.0 接口的 egl_wayland_texture3_1.c
    • 2. xdg-shell-client-protocol.h 和 xdg-shell-protocol.c
    • 3. 编译
    • 4. 运行
  • 总结
  • 参考资料


前言

本文主要介绍如何在一个wayland client 里面使用 egl + opengles 读取一个 pattern 图片数据进行纹理贴图,在阅读本篇文章之前,建议先读一下之前的文章 《wayland(xdg_wm_base) + egl + opengles 最简实例(一)》
软硬件环境
硬件:PC
软件:ubuntu22.04 weston9.0 opengles2.0/3.0 egl1.4


一、使用gstreamer 获取 pattern 图片

在ubuntu 下执行如下命令可以获取一张格式为RGB888, 分辨率为640x480 的pattern 图片
gst-launch-1.0 videotestsrc num-buffers=1 foreground-color=0 ! video/x-raw,format=RGB, width=640,height=480 ! filesink location=./pattern_640x480.rgb
如下图所示:
在这里插入图片描述
在PC 端使用YUV player 软件工具(格式和分辨率分别设置为RGB24和640x480)打开该图片的效果如下图所示
在这里插入图片描述

二、代码实例

1. pattern 图片作为纹理数据源的代码实例

1.1 基于opengles2.0 接口的 egl_wayland_texture2_1.c

#include <wayland-client.h>
#include <wayland-server.h>
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "xdg-shell-client-protocol.h"#define WIDTH 800
#define HEIGHT 600struct wl_display *display = NULL;
struct wl_compositor *compositor = NULL;
struct xdg_wm_base *wm_base = NULL;
struct wl_registry *registry = NULL;struct window {struct wl_surface *surface;struct xdg_surface *xdg_surface;struct xdg_toplevel *xdg_toplevel;struct wl_egl_window *egl_window;
};// Index to bind the attributes to vertex shaders
const unsigned int VertexArray = 0;static void
xdg_wm_base_ping(void *data, struct xdg_wm_base *shell, uint32_t serial)
{xdg_wm_base_pong(shell, serial);
}/*for xdg_wm_base listener*/
static const struct xdg_wm_base_listener wm_base_listener = {xdg_wm_base_ping,
};/*for registry listener*/
static void registry_add_object(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) 
{if (!strcmp(interface, "wl_compositor")) {compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);} else if (strcmp(interface, "xdg_wm_base") == 0) {wm_base = wl_registry_bind(registry, name,&xdg_wm_base_interface, 1);xdg_wm_base_add_listener(wm_base, &wm_base_listener, NULL);}
}void registry_remove_object(void *data, struct wl_registry *registry, uint32_t name) 
{}static struct wl_registry_listener registry_listener = {registry_add_object, registry_remove_object};static void
handle_surface_configure(void *data, struct xdg_surface *surface,uint32_t serial)
{xdg_surface_ack_configure(surface, serial);
}static const struct xdg_surface_listener xdg_surface_listener = {handle_surface_configure
};static void
handle_toplevel_configure(void *data, struct xdg_toplevel *toplevel,int32_t width, int32_t height,struct wl_array *states)
{
}static void
handle_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel)
{
}static const struct xdg_toplevel_listener xdg_toplevel_listener = {handle_toplevel_configure,handle_toplevel_close,
};bool initWaylandConnection()
{	if ((display = wl_display_connect(NULL)) == NULL){printf("Failed to connect to Wayland display!\n");return false;}if ((registry = wl_display_get_registry(display)) == NULL){printf("Faield to get Wayland registry!\n");return false;}wl_registry_add_listener(registry, &registry_listener, NULL);wl_display_dispatch(display);if (!compositor){printf("Could not bind Wayland protocols!\n");return false;}return true;
}bool initializeWindow(struct window *window)
{initWaylandConnection();window->surface = wl_compositor_create_surface (compositor);window->xdg_surface = xdg_wm_base_get_xdg_surface(wm_base, window->surface);if (window->xdg_surface == NULL){printf("Failed to get Wayland xdg surface\n");return false;} else {xdg_surface_add_listener(window->xdg_surface, &xdg_surface_listener, window);window->xdg_toplevel =xdg_surface_get_toplevel(window->xdg_surface);xdg_toplevel_add_listener(window->xdg_toplevel,&xdg_toplevel_listener, window);xdg_toplevel_set_title(window->xdg_toplevel, "egl_wayland_texture");}return true;}void releaseWaylandConnection(struct window *window)
{if(window->xdg_toplevel)xdg_toplevel_destroy(window->xdg_toplevel);if(window->xdg_surface)xdg_surface_destroy(window->xdg_surface);wl_surface_destroy(window->surface);xdg_wm_base_destroy(wm_base);wl_compositor_destroy(compositor);wl_registry_destroy(registry);wl_display_disconnect(display);
}bool createEGLSurface(EGLDisplay eglDisplay, EGLConfig eglConfig, EGLSurface *eglSurface, struct window *window)
{window->egl_window = wl_egl_window_create(window->surface, WIDTH, HEIGHT);if (window->egl_window == EGL_NO_SURFACE) { printf("Can't create egl window\n"); return false;} else {printf("Created wl egl window\n");}*eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, window->egl_window, NULL);return true;
}bool create_textures(GLuint *textureId)
{GLuint width, height;GLbyte *data;GLint fd;width = 640;height = 480;fd = open("./pattern_640x480.rgb", O_RDONLY);if(fd < 0) {printf("open failed\n");return false;}data = (GLbyte *)malloc(width * height * 3);if(<

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/681294.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

大模型LoRA知识

什么是 LoRA&#xff1f; LoRA&#xff08;low-rank adaptation of large language models&#xff09;是一种针对大型语言模型进行低秩适应的技术。大型语言模型通常具有数十亿个参数&#xff0c;这使得它们在计算和存储方面非常昂贵。低秩适应的目标是通过将语言模型的参数矩…

Gateway微服务网关

Spring Cloud Gateway Spring Cloud Gateway 是 Spring Cloud生态系统中的网关&#xff0c;它是基于Spring 5.0、SpringBoot 2.0和Project Reactor等技术开发的&#xff0c;旨在为微服务架构提供一种简单有效的、统一的API路由管理方式&#xff0c;并为微服务架构提供安全、监…

【力扣】5.最长回文子串

这道题我主要是通过动态规划来进行解题&#xff0c;看了我好久&#xff08;解析&#xff09;&#xff0c;生疏了呀。 首先就是判断一个字符串是不是回文&#xff0c;我们可以设置两个指针&#xff0c;从前往后进行判断即可&#xff0c;运用暴力解题法&#xff0c;这里运用的动…

【生产实测可用】Redis修改集群弱口令

起因 漏扫redis连接发现弱口令需要修改 先连上去看看是空口令还是弱口令 redis-cli -p 6379 -h a.b.c.d info sentinel找到启动服务器的配置文件 cp -av /app/redis-7001/redis.conf /app/redis-7001/redis.conf.bak20240207 echo "requirepass 口令" >>/a…

Gitee的使用教程(简单详细)

1.安装git&#xff08;我的电脑自带git&#xff0c;我没弄这步QAQ&#xff09; Git (git-scm.com)https://git-scm.com/ 安装好后在桌面点击鼠标右键会出现git GUI 和 git Bash&#xff08;没有的话点击显示更多选项&#xff09; 2.去gitee上注册一个账号 工作台 - Gitee.co…

Qt杂记——TCP

1. if(m_tcpSocket!nullptr){m_tcpSocket->flush();m_tcpSocket->abort();m_tcpSocket->deleteLater();m_tcpSocket nullptr;} &#xff08;1&#xff09;m_tcpSocket->flush() 调用m_tcpSocket->flush()函数可以强制将发送缓冲区中的数据立即发送出去&#…

toString方法

Object类中定义有public String toString()方法&#xff0c;其返回值是String类型。Object类中toString方法的源码为&#xff1a; public String toString(){return getClass().getName() "" Integer.toHexString(hashCode); } 根据如上源码得知&#xff0c;默认…

Spring Boot 笔记 008 创建接口_获取用户信息

1.1.1 编写userinfo接口 1.1.2 User实体类中增加转json忽略password注释 package com.geji.pojo;import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data;import java.time.LocalDateTime;//lombok 在…

C#查找字符串中的所有数字: 面向对象的自定义方法 vs 使用char.IsDigit()方法

目录 一、涉及到的方法 1.面向对象的自定义方法 2.面向对象编程技术定义 3.使用char.IsDigit()方法 二、实例 1.源码 2.生成效果 一、涉及到的方法 1.面向对象的自定义方法 查找字符串中的所有数字时&#xff0c;首先将所有数字存储到一个字符串数组中&#xff0c;然后…

【DDD】学习笔记-事件风暴与领域分析建模

在确定了全景事件流之后&#xff0c;可以在战略设计层面继续精进&#xff0c;鉴别出领域与限界上下文的边界&#xff0c;进入战术设计阶段的领域分析建模。 事件风暴的分析模型要素 通过事件风暴进行领域分析建模&#xff0c;其核心的模型要素就是“事件”。除此之外&#xf…

Windows平台git clone文件路径太长报错

问题描述 在Windows下拉取一些比较大的开源项目经常会提示文件路径太长&#xff08;filename too long&#xff09;&#xff0c;然后死活都不成功 解决办法 1.配置git git config --system core.longpaths true2.修改文件C:\Program Files\Git\etc\gitconfig&#xff08;需…

计算机视觉基础:矩阵运算

矩阵及其表示方式 一个矩阵是由行(row)和列(column)组成的一个矩形数组&#xff0c;通常包含数字。我们可以用大写字母&#xff08;如 A、B&#xff09;来表示一个矩阵。例如&#xff0c;矩阵 A 可能看起来像这样&#xff1a; A [ a11 a12 a13 ][ a21 a22 a23 ][ a31 a32 a3…

Windows 虚拟桌面信息(一)分析注册表

目录 前言 一、理论分析 二、代码实现 总结 本文为原创文章&#xff0c;转载请注明出处&#xff1a; https://blog.csdn.net/qq_59075481/article/details/136110636 前言 Win 10/11 的虚拟桌面微软暂时没有开放接口&#xff0c;有很多信息对开发者是闭塞的&#xff0c;…

阿里文档类图像的智能识别,文档分类自定义分类器

阿里云文档类图像智能识别服务为用户提供了强大的文档处理能力&#xff0c;可以将文档图像中的文本内容、表格数据和结构化信息自动识别并提取出来。而自定义分类器则允许用户根据自己的需求&#xff0c;训练出更适合自己场景的文档分类模型。本文将详细介绍阿里云文档类图像智…

Python学习之路-爬虫提高:selenium

Python学习之路-爬虫提高:selenium 什么是selenium Selenium是一个Web的自动化测试工具&#xff0c;最初是为网站自动化测试而开发的&#xff0c;Selenium 可以直接运行在浏览器上&#xff0c;它支持所有主流的浏览器&#xff08;包括PhantomJS这些无界面的浏览器&#xff09…

react【六】 React-Router

文章目录 1、Router1.1 路由1.2 认识React-Router1.3 Link和NavLink1.4 Navigate1.5 Not Found页面配置1.6 路由的嵌套1.7 手动路由的跳转1.7.1 在函数式组件中使用hook1.7.2 在类组件中封装高阶组件 1.8 动态路由传递参数1.9 路由的配置文件以及懒加载 1、Router 1.1 路由 1.…

面试经典150题——无重复字符的最长子串

我生来就是高山而非溪流&#xff0c;我欲于群峰之巅俯视平庸的沟壑 1. 题目描述 2. 题目分析与解析 2.1 思路一——暴力解法 看到这个题目&#xff0c;我们是不是发现和上一篇内容刚刚讲过的长度最小的子数组题目很像&#xff1f;首先自然的暴力解法&#xff0c;就是遍历字符…

音视频基础

本篇文章我们来讲一下音视频基础 像素点: 将以下图片的美女眼睛放大 能够看到一个一个的小方块 这就是像素点 照片像素宽像素点*高像素点 像素点 代码实例&#xff1a; #include <opencv2/opencv.hpp>int main() {// 创建一个200x100的黑色图像cv::Mat image(100, 200,…

大模型基础知识

主流的开源模型体系 GPT&#xff08;Generative Pre-trained Transformer&#xff09;系列&#xff1a;由OpenAI发布的一系列基于Transformer架构的语言模型&#xff0c;包括GPT、GPT-2、GPT-3等。GPT模型通过在大规模无标签文本上进行预训练&#xff0c;然后在特定任务上进行…

web3知识体系汇总

web3.0知识体系 1.行业发展 2. web3的特点&#xff1a; 1、统一身份认证系统 2、数据确权与授权 3、隐私保护与抗审查 4、去中心化运行 Web3.0思维技术思维✖金融思维✖社群思维✖产业思维”&#xff0c;才能从容理解未来Web3.0时代的大趋势。 3.技术栈 Web3.jsSolidit…