背景:除了利用平台的截屏功能外,kanzi自带的截屏功能并不好用,而且Texture的离屏渲染,也无法获取本地的纹理数据,似乎直接发给了GPU。
需求:kanzi画面离屏渲染,将纹理数据保存到本地图片。
一、创建kanzi插件
创建插件工程参考 使用kanzi开发仪表HMI插件
插件属性
static kanzi::PropertyType<kanzi::string> NameProperty; //图片名字
static kanzi::PropertyType<bool> ReSaveProperty; //是否保存图片
static kanzi::PropertyType<int> CaptureImgWidth; //图片宽度
static kanzi::PropertyType<int> CaptureImgHeight; //图片高度
1.1 引入glad,设置framebuffer
gladLoadGL();
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
kzLogDebug(("m_fbo={}", m_fbo));
const int width = getProperty(CaptureImgWidth);
const int height = getProperty(CaptureImgHeight);
imageData = (unsigned char*)malloc(width * height * 4); // 4 bytes per pixel
flippedData = (unsigned char*)malloc(width * height * 4); // 新的图像数据数组
glGenTextures(1, &m_textureColorBuffer);
glBindTexture(GL_TEXTURE_2D, m_texture