Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>well - from my experience you cannot just grab the pixels that are in the buffer right now you need to reestablish the right context, draw and grab THEN before finally releasing the context</p> <p>=> This is mainly true for the device and ios6 in particular</p> <pre><code>EAGLContext* previousContext = [EAGLContext currentContext]; [EAGLContext setCurrentContext: self.context]; [self fillBuffer:sender]; //GRAB the pixels here [EAGLContext setCurrentContext:previousContext]; </code></pre> <p>alternatively (thats how I do it) create a new FrameBuffer, fill THAT and grab pixels from THERE</p> <pre><code>GLuint rttFramebuffer; glGenFramebuffers(1, &amp;rttFramebuffer); glBindFramebuffer(GL_FRAMEBUFFER, rttFramebuffer); [self fillBuffer:self.displayLink]; size_t size = viewportHeight * viewportWidth * 4; GLubyte *pixels = malloc(size*sizeof(GLubyte)); glPixelStorei(GL_PACK_ALIGNMENT, 4); glReadPixels(0, 0, viewportWidth, viewportHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Restore the original framebuffer binding glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glDeleteFramebuffers(1, &amp;rttFramebuffer); size_t bitsPerComponent = 8; size_t bitsPerPixel = 32; size_t bytesPerRow = viewportWidth * bitsPerPixel / bitsPerComponent; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast; CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, size, ImageProviderReleaseData); CGImageRef cgImage = CGImageCreate(viewportWidth, viewportHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, bitmapInfo, provider, NULL, true, kCGRenderingIntentDefault); CGDataProviderRelease(provider); UIImage *image = [UIImage imageWithCGImage:cgImage scale:self.contentScaleFactor orientation:UIImageOrientationDownMirrored]; CGImageRelease(cgImage); CGColorSpaceRelease(colorSpace); </code></pre> <p>Edit: removed call to presentBuffer</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload