jokerdc
jokerdc

Reputation: 261

Got a crash when using GPUImageFilter

I started from Brad Larson's Tutorial on Github.Here when i added these code into my project

- (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:self.view.bounds];

[self.view addSubview:filteredVideoView];

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

[videoCamera startCameraCapture];
}

and i got a crash in the methods - (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString;

With log outputted as follow:

 013-08-04 17:17:37.567 ViewPack[36088:907] Failed to load vertex shader
2013-08-04 17:17:37.570 ViewPack[36088:907] Failed to compile fragment shader
2013-08-04 17:17:37.572 ViewPack[36088:907] Program link log: ERROR: OpenGL ES 2.0        requires exactly one vertex and one fragment shader to validly link.
2013-08-04 17:17:37.573 ViewPack[36088:907] Fragment shader compile log: (null)
2013-08-04 17:17:37.574 ViewPack[36088:907] Vertex shader compile log: (null)
2013-08-04 17:17:37.576 ViewPack[36088:907] *** Assertion failure in -[GPUImageFilter   initWithVertexShaderFromString:fragmentShaderFromString:],  /Users/dachang/Desktop/Files/Libs/GPUImage-master/framework/Source/GPUImageFilter.m:97

I think i had correctly add GPIImage into my project, cause i do can import all those headers. I don't know what ' OpenGL ES 2.0 requires exactly one vertex and one fragment shader to validly link.' means.(and I cannot find CustomShader.fsh file)

Can anybody please help..thanks a lot..

Upvotes: 0

Views: 2475

Answers (1)

Brad Larson
Brad Larson

Reputation: 170309

The above code tries to create a filter from a custom fragment shader file (in this case, CustomShader.fsh). For this to work, you need to have a file by that name in your project, and need to make sure that it is in the copying resources build phase for your project, not the compiling sources build phase. It also must be a valid fragment shader of the style expected by the project. The MultiViewFilterExample has one of these.

I should note that this is only necessary if you want to create your own custom fragment shader for a filter. As an alternative, you can use one of the 100+ other filters that come with the framework, and avoid this process.

Upvotes: 3

Related Questions