我有一个问题,有openGL视图.我有两个openGL视图.第二个视图作为子视图添加到主视图中.两个opengl视图在两个不同的opengl上下文中绘制.我需要使用两个opengl视图捕获屏幕.
问题是,如果我尝试在上下文中呈现一个CAEAGLLayer,如下所示:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 1*(self.frame.size.width*0.5), 1*(self.frame.size.height*0.5));
CGContextScaleCTM(context, 3, 3);
CGContextTranslateCTM(context, abcd, abcd);
CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.myOwnView.layer;
[eaglLayer renderInContext:context];
Run Code Online (Sandbox Code Playgroud)
这是行不通的.如果我看到上下文(将输出作为图像),则缺少opengl层中的内容.但我发现输出图像中的工具栏和2D图像附加到视图中.我不确定这个问题.请帮忙.
我试过了:
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(metalLayer.bounds.size,false,scale)
// metalLayer.renderInContext(UIGraphicsGetCurrentContext()!)
// self.view.layer ...
metalLayer.presentationLayer()!.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
Run Code Online (Sandbox Code Playgroud)
但结果是一个空截图.你能帮忙的话,我会很高兴!
请记住,我想拍摄CAMetalLayer的快照