wayland(xdg_wm_base) + egl + opengles 光照模型实例(十五)

这篇具有很好参考价值的文章主要介绍了wayland(xdg_wm_base) + egl + opengles 光照模型实例(十五)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


前言

本文主要介绍如何使用 wayland(xdg_wm_base) + egl + opengles3.0 绘制一个使用冯氏光照模型(Phong Lighting Model)的绕Y轴旋转的正方体,主要涉及环境(Ambient)、漫反射(Diffuse)和镜面(Specular)光照,使用一个固定位置和颜色的光源。
软硬件环境:
硬件:PC
软件:ubuntu22.04 egl1.4 opengles3.0 weston9.0


一、获取 glm 库文件

glm是一个C++数学库,用于进行OpenGL开发时常用的数学计算,例如向量、矩阵、四元数等。它提供了许多方便的函数和工具,可以简化在OpenGL程序中进行数学计算的过程。在使用 glm之前,您需要包含适当的 glm 头文件(glm 库就是一个头文件,没有.so库)。获取 glm 相关的头文件,有以下两种方式:

  1. ubuntu 上安装 glm 库
    具体的安装过程,可以查看《opengles 顶点坐标变换常用的矩阵(九)》 这篇文章
  2. 从 github 获取
    直接从 glm github 仓库地址 下载即可

二、使用环境(Ambient)、漫反射(Diffuse)和镜面(Specular)光照效果的3d 立方体

1. egl_wayland_light.cpp

egl_wayland_light.cpp 代码如下文章来源地址https://www.toymoban.com/news/detail-840031.html

#include <wayland-client.h>
#include <wayland-server.h>
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <GLES3/gl3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xdg-shell-client-protocol.h"
#include "Matrix.h"


#include <glm/vec3.hpp> // glm::vec3
#include <glm/vec4.hpp> // glm::vec4
#include <glm/gtc/type_ptr.hpp>

#define WIDTH 800
#define HEIGHT 600

struct wl_display *display = NULL;
struct wl_compositor *compositor = NULL;
struct xdg_wm_base *wm_base = NULL;
struct wl_registry *registry = NULL;

//opengles global var

GLuint projectionLocation;
GLuint modelLocation;
GLuint viewLocation;
GLuint simpleCubeProgram;


float projectionMatrix[16];
float modelMatrix[16];
float viewMatrix[16];
float angleX = 30.0f;
float angleY = 0.0f;
float angleZ = 0.0f;


struct window {
   
	struct wl_surface *surface;
    struct xdg_surface *xdg_surface;
	struct xdg_toplevel *xdg_toplevel;
	struct wl_egl_window *egl_window;
};

// Light parameters
glm::vec3 lightPos(0.0f, 3.0f, 0.0f);          // 建立一个在立方体正上方的光源(Y轴正方向上位置为3.0处)
glm::vec3 lightColor(1.0f, 1.0f, 1.0f);        //光源颜色为白色

//viewPos parameters
glm::vec3 viewPos(0.0f, 0.0f, 3.0f);

// Object parameters
glm::vec3 objectColor(1.0f, 0.0f, 0.0f);

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 = (struct wl_compositor *)wl_registry_bind(registry, name, &wl_compositor_interface, 1);
    } else if (strcmp(interface, "xdg_wm_base") == 0) {
   
        wm_base = (struct xdg_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)
{
   
	//struct window *window = data;

	xdg_surface_ack_configure(surface, serial);

	//window->wait_for_configure = false;
}

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

到了这里,关于wayland(xdg_wm_base) + egl + opengles 光照模型实例(十五)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • wayland(xdg_wm_base) + egl + opengles 纹理贴图最简实例(三)

    本文主要介绍如何在一个wayland client 里面使用 egl + opengles 实现一个最简单的纹理贴图功能,在阅读本篇文章之前,建议先读一下之前的文章 《wayland(xdg_wm_base) + egl + opengles 最简实例》 软硬件环境 硬件:PC 软件:ubuntu22.04 weston9.0 opengles2.0 egl1.4 纹理贴图(Texture Mapping)是计算

    2024年02月20日
    浏览(8)
  • wayland(xdg_wm_base) + egl + opengles 使用FBO渲染到纹理实例(六)

    本文主要介绍 如何在 opengles 中使用FBO 实现渲染到纹理的功能 软硬件环境: 硬件:PC 软件:ubuntu22.04 opengles3.0 egl1.4 FBO(Framebuffer Object)是OpenGL的一个扩展,它允许我们将渲染结果直接绘制到一个纹理或者渲染缓冲对象中,而不是默认的帧缓冲。 使用FBO可以实现一些高级的渲

    2024年02月20日
    浏览(19)
  • wayland(xdg_wm_base) + egl + opengles——dma_buf 作为纹理数据源(五)

    wayland(xdg_wm_base) + egl + opengles——dma_buf 作为纹理数据源(五)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 `本文主要描述如何在一个wayland client 中将一个 dma_buf import 作为一个 opengles texture 数据源 软硬件环境 硬件:aarch64 软件:linux5.10 opengles2.0/3.0 egl1.5 如下图所示,EGL 中 import dma_buf 作为 opengles texture ,主要

    2024年02月20日
    浏览(26)
  • 记录解决运行Qt程序出现警告提示“Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland t”

    记录解决运行Qt程序出现警告提示“Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland t”

    运行Qt程序是出现警告提示“Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.”,虽然并不影响程序的运行和显示,但是看着碍眼啊,于是上网搜索了一下解决办法,记录一下 这个警告提示是关于在 Gnome 桌面环境下运行 Qt 程序时的一种提示信

    2024年04月12日
    浏览(15)
  • 【Android OpenGL开发】OpenGL ES与EGL介绍

    【Android OpenGL开发】OpenGL ES与EGL介绍

    OpenGL(Open Graphics Library)是一个跨编程语言、跨平台的编程图形程序接口,主要用于图像的渲染。 Android提供了简化版的OpenGL接口,即OpenGL ES。 早先定义 OpenGL ES 是 OpenGL 的嵌入式设备版本,用于移动端平台(Android、iOS),但由于嵌入式设备要求的是高性能,所以一些其它纯

    2024年02月04日
    浏览(10)
  • wayland 之opengl es

       EGL 是 OpenGL ES 渲染 API 和本地窗口系统(native platform window system)之间的一个中间接口层,它主要由系统制造商实现。 使用 EGL 绘图的基本步骤 Display(EGLDisplay) 是对实际显示设备的抽象。 Surface(EGLSurface)是对用来存储图像的内存区域 FrameBuffer 的抽象,包括 Color Buffer, Sten

    2024年02月09日
    浏览(7)
  • OpenGL ES EGL eglCreatePbufferSurface

    OpenGL ES EGL eglCreatePbufferSurface

    目录 一. EGL 前言 二. EGL 绘制流程简介 三.eglCreatePbufferSurface 函数简介 1.eglCreatePbufferSurface 简介 2.eglCreatePbufferSurface 和 eglCreateWindowSurface 区别 四.eglCreatePbufferSurface 使用 五.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : O

    2024年02月01日
    浏览(12)
  • OpenGL ES EGL eglCreateContext

    OpenGL ES EGL eglCreateContext

    目录 一. EGL 前言 二. EGL 绘制流程简介 三.eglCreateContext 函数简介 1.关于属性列表 attribList 2.关于返回值 四.eglCreateContext 函数使用 五.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 OpenGL ES 特效 零基础 Op

    2023年04月08日
    浏览(8)
  • OpenGL ES EGL eglMakeCurrent

    OpenGL ES EGL eglMakeCurrent

    目录 一. EGL 前言 二. EGL 绘制流程简介 三.eglMakeCurrent 函数简介 1.eglMakeCurrent 简介 2.eglMakeCurrent 实现 3.eglMakeCurrent 使用 四.关于多个 EGLContext 五.共享 EGLContext 六.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目

    2024年02月14日
    浏览(10)
  • OpenGL ES EGL eglCreateWindowSurface

    OpenGL ES EGL eglCreateWindowSurface

    一. EGL 前言 二. EGL 绘制流程简介 三.eglCreateWindowSurface 函数简介 1.eglCreateWindowSurface 函数 2.EGLSurface 分类 四.eglCreateWindowSurface 函数使用 五.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 OpenGL ES 特效 零基础

    2023年04月10日
    浏览(8)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包