我正在使用 AVFoundation 从相机捕获信息,将其传递给 CIFilter 以用 alpha 级别为 0 的像素替换较暗的像素,并将其显示在 GLKView 上。
包含的视图控制器是一个 GLKViewController 但程序的核心从函数开始:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
@autoreleasepool {
CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *image = [CIImage imageWithCVPixelBuffer:pixelBuffer options:[NSDictionary dictionaryWithObject:(id)kCFNull forKey:kCIImageColorSpace]];
image = [image imageByApplyingTransform:CGAffineTransformMakeRotation(-M_PI/2.0)];
CGPoint origin = [image extent].origin;
image = [image imageByApplyingTransform:CGAffineTransformMakeTranslation(-origin.x, -origin.y)];
[self.replaceDarkColorWithTransparentFilter setValue:image forKey:@"inputImage"];
image = self.replaceDarkColorWithTransparentFilter.outputImage;
[self.ciContext drawImage:image inRect:CGRectMake(0.0f, 0.0f, 480.0f, 640.0f) fromRect:[image extent]];
[self.eaglContext presentRenderbuffer:GL_RENDERBUFFER];
[self.replaceDarkColorWithTransparentFilter setValue:nil forKey:@"inputImage"];
}
}
在 GLKViewController 中,我使用以下方法初始化渲染缓冲区:
glGenRenderbuffers(1, &_renderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);
结果是旧图像没有被清除和显示。结果如下所示:http ://d.pr/i/M02z这正常吗?不应该清除旧的上下文并重新开始吗?
我尝试glFlush();
过更新并glkView:(GLKView *)view drawInRect:(CGRect)rect
尝试为 CIContext 中的图像绘制 nil 无济于事。
有什么我想念的吗?