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.

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top