与带有OpenGL ES(EGL)的eglCreatePbufferSurface和eglCreatePixmapSurface的区别 [英] Difference from eglCreatePbufferSurface and eglCreatePixmapSurface with OpenGL ES(EGL)

查看:2214
本文介绍了与带有OpenGL ES(EGL)的eglCreatePbufferSurface和eglCreatePixmapSurface的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,我需要通过软件渲染在opengl es2上进行一些屏幕外工作(仅具有CPU,没有GPU).问题是我可以在没有GPU的情况下使用pbuffer吗?另外,如何在绘制内容后直接保存到png文件.请帮忙给我演示.

I am having a problem where I need to some off-screen work with opengl es2 by software rendering(Only has CPU, no GPU). The question is can I use pbuffer without GPU? Also, how to directly save to a png file after drawing something. Please help and give me a demo.

推荐答案

首先,使用EGL创建一个屏幕外缓冲区:

First, use EGL to create an off-screen buffer:

eglCreatePbufferSurface(display, config, PBufAttribs); 

然后读取缓冲区:

   GLint size;
   size = esContext->width * esContext->height * 4;
   GLubyte *data = (GLubyte*)malloc(size);
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glReadPixels(0,0,esContext->width,esContext->height,GL_RGB,GL_UNSIGNED_BYTE,data);

最后保存到像素缓冲区的bmp文件. (提醒:在24位bmp图像中,顺序为BGR,而不是RGB;因此需要将图像数据从BGR切换为RGB.)

The last save to pixel buffer to a bmp file. (reminder: In 24 bit bmp image, the order is BGR, not RGB; So need to switch the image data from BGR to RGB.)

这篇关于与带有OpenGL ES(EGL)的eglCreatePbufferSurface和eglCreatePixmapSurface的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆