Difference from eglCreatePbufferSurface and eglCreatePixmapSurface with OpenGL ES(EGL)

末鹿安然 提交于 2019-12-10 18:34:00

问题


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.


回答1:


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

eglCreatePbufferSurface(display, config, PBufAttribs); 

Then read the buffer:

   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);

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.)



来源:https://stackoverflow.com/questions/12906971/difference-from-eglcreatepbuffersurface-and-eglcreatepixmapsurface-with-opengl-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!