Http://www.cnblogs.com/CoderAlex/p/6604618.html
In general, we use OpenGL to draw the rendered picture onto the screen, but sometimes we don't want to show the results, so we need to use off-screen rendering.
Normally, we use the screen, which is a Caeagllayer object, as the render target, and the off-screen rendering is to reposition the render target, place the memory space as a render target, and then retrieve the image from memory.
In the off-screen rendering process need to use to FBO, unfamiliar friends can first consult FBO related information http://blog.csdn.net/dreamcs/article/details/7691690
Let's take a look at how to do off-screen rendering:
Glgenrenderbuffers (1, &_colorbufferrender); Glbindrenderbuffer (Gl_renderbuffer, _colorbufferrender);// [_context Renderbufferstorage:gl_renderbuffer Fromdrawable:_ealayer]; Glgenframebuffers (1, &_framebuffer); Glbindframebuffer (Gl_framebuffer, _framebuffer); Glrenderbufferstorage (Gl_renderbuffer, Gl_rgb8_oes, _drawablewidth, _drawableheight); Glframebufferrenderbuffer (Gl_framebuffer, gl_color_attachment0, Gl_renderbuffer, _ Colorbufferrender);
In fact, the process is simple, allocating memory for Renderbuffer, and then mounting the renderbuffer to framebuffer so that the render target is directed from the original Caealyaer to the memory allocated for Renderbuffer.
There seems to be a texture as a render target, unfortunately did not study understand, there will be friends can leave a message to teach me a bit.
The rest of the process does not make any difference, and after the rendering is finished, the image is taken from memory.
Nsinteger datalength = self.drawablewidth * Self.drawableheight * 4; Glubyte *buffer = (Glubyte *) malloc (datalength * sizeof (glubyte)); Glreadpixels (0, 0, self.drawablewidth, Self.drawableheight, Gl_rgba, gl_unsigned_byte, buffer); Cgdataproviderref Provider = Cgdataprovidercreatewithdata (NULL, Buffer, datalength, NULL); int bitspercomponent = 8; int bitsperpixel = 32; int bytesperrow = 4 * self.drawablewidth; Cgcolorspaceref colorspaceref = Cgcolorspacecreatedevicergb (); Cgbitmapinfo bitmapinfo = Kcgbitmapbyteorderdefault; Cgcolorrenderingintent renderingintent = Kcgrenderingintentdefault; Cgimageref imageref = cgimagecreate (Self.drawablewidth, Self.drawableheight, Bitspercomponent, BitsPerPixel, Bytesperrow, Colorspaceref, Bitmapinfo, provider, NULL, True, renderingintent); UIImage *myimage = [UIImage imagewithcgimage:imageref];
iOS-----opengl--opengl ES iOS entry 4---> Off-screen rendering