0

In objective-C, I was able to render the EAGLContext to UIImage using glReadPixels to read the pixel data from the framebuffer, creating a CGImage using the pixel data, and then retrieving a UIImage from the context.

I am trying a new method in Swift, but it is returning an empty image. I would like to create a GLKView from the EAGLContext, and then use 'snapshot' to get the UIImage. The “myEaglContext” passed into the GLKView constructor has data on it.

let glkView = GLKView(frame: CGRect(x: 0,y: 0,width: self.frame.size.width,height: self.frame.size.height),context: myEaglContext)

glkView.bindDrawable()
glkView.display()

let image : UIImage = glkView.snapshot

Does anyone know why this approach is not working?

BDL
  • 21,052
  • 22
  • 49
  • 55
CTRLALTDELx64
  • 93
  • 1
  • 7
  • First, I've never known about the `snapshot` function, so I'm not an expert. (And thanks for this, I'll check it out.) I'm rather new to OpenGL, CoreImage, CIContexts... only two years working with them. I've programmed *many* languages and can (reluctantly) translate Obj-C. That all said, I've noticed a few things I don't quite know why - the first being don't translate directly from `CIImage` to `UIImage`. Have you tried using `CIContext.createCGImage` instead? –  May 23 '18 at 18:03
  • @dfd The createCGImage function takes a CIImage as input but I only have the EAGLContext. I can convert the EAGLContext to CIContext but I still won’t have a CIImage. Is there a way to make a CIImage from the CIContext? – CTRLALTDELx64 May 23 '18 at 18:56
  • Not that I'm aware of, sorry. I did say I'm not an expert. :-( –  May 23 '18 at 20:06

0 Answers0