0

我需要显示实时摄像机源。我使用了 GPUImage,当我执行代码时出现此错误。我参考了一些文档,并在 viewDidLoad 中编写了代码。当我打开应用程序时,它崩溃了。

 - (void)viewDidLoad
    {
        [super viewDidLoad];
    GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"CustomShader"];
    GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];

    // Add the view somewhere so it's visible

    [videoCamera addTarget:customFilter];
    [customFilter addTarget:filteredVideoView];

    [videoCamera startCameraCapture];

    }

日志:

Failed to load vertex shader
  Failed to compile fragment shader
 Program link log: ERROR: OpenGL ES 2.0 requires exactly one vertex and one fragment shader to validly link.
 Fragment shader compile log: (null)
 Vertex shader compile log: (null)
  *** Assertion failure in -[GPUImageFilter initWithVertexShaderFromString:fragmentShaderFromString:], /Users/ranganathagv/Projects/MobileApp/test/iOS/View/28May_GPU/BradLarson-GPUImage-f67cbd9/framework/Source/GPUImageFilter.m:76
  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Filter shader link failed'
4

1 回答 1

1

确保已将着色器添加到 Copy Bundle Resources 构建阶段。默认情况下,Xcode 会尝试将它们编译为源代码文件,而不是像应有的那样将它们包含在您的应用程序包中。

于 2014-05-28T11:36:45.673 回答