iOS-----opengl--opengl ES iOS entry 4---> Off-screen rendering

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.