我试图自己教Xcode,Objective-C,iOS应用程序开发和GLSL。 (我可能不太可取,; --)我一直在修改GLCameraRipple的例子,并且迄今取得了很大的成功!但是当我试图创建一些新的顶点和片段着色器时,我今天陷入了困境。为什么Xcode不能识别这些着色器?
该示例附带名为“Shader.vsh”和“Shader.fsh”的着色器。我用File-> Duplicate来制作它们的副本,我分别称它们为“Reflection.vsh”和“Reflection.fsh”。问题是我无法让Xcode识别新的着色器。此代码,它加载了原有的顶点着色器,工作得很好:
vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"];
NSLog(@"Original vertex shader should be here: %@", vertShaderPathname);
if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname]) {
NSLog(@"Failed to compile original vertex shader");
return NO;
}
但这个代码,它试图加载我新“Reflection.vsh”着色器失败。具体来说,reflectVertShaderPathname字符串会返回值(null)。
reflectVertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Reflection" ofType:@"vsh"];
NSLog(@"Reflection vertex shader should be here: %@", reflectVertShaderPathname);
if (![self compileShader:&reflectVertShader type:GL_VERTEX_SHADER file:reflectVertShaderPathname]) {
NSLog(@"Failed to compile reflection vertex shader");
return NO;
}
我该做些什么才能做到这一点?我甚至不知道从哪里开始:Xcode是否无法在为iPad编译此文件时将新着色器包含在NSBundle中?我必须调用什么魔法巫术来说服Xcode加载我的新着色器? (或者我完全在错误的地方寻找答案?)有没有其他人遇到过类似的问题?
检查了“project.pbxproj”文件中的文本编辑器,我发现那里的着色器被区别对待的一个部分:
/* Begin PBXResourcesBuildPhase section */
B66E3E2C13E9E79C00D2ACF0 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B66E3E4713E9E79C00D2ACF0 /* Shader.fsh in Resources */,
B66E3E4913E9E79C00D2ACF0 /* Shader.vsh in Resources */,
B66E3E4F13E9E79C00D2ACF0 /* RippleViewController_iPhone.xib in Resources */,
B66E3E5213E9E79C00D2ACF0 /* RippleViewController_iPad.xib in Resources */,
B6388B2C141AB58300DA02FB /* Icon-72.png in Resources */,
B6388B2D141AB58300DA02FB /* Icon-Small-50.png in Resources */,
B6388B2E141AB58300DA02FB /* Icon-Small.png in Resources */,
B6388B2F141AB58300DA02FB /* [email protected] in Resources */,
B6388B30141AB58300DA02FB /* Icon.png in Resources */,
B6388B31141AB58300DA02FB /* [email protected] in Resources */,
C3E55C21175C49F9007C299D /* [email protected] in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
B66E3E2A13E9E79C00D2ACF0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B66E3E4113E9E79C00D2ACF0 /* main.m in Sources */,
B66E3E4513E9E79C00D2ACF0 /* AppDelegate.m in Sources */,
B66E3E4C13E9E79C00D2ACF0 /* RippleViewController.m in Sources */,
B6670DB413E9FD9F00AEF9EC /* RippleModel.m in Sources */,
C359BF4D175EA71C00D801B9 /* Reflection.fsh in Sources */,
C359BF4F175EA72A00D801B9 /* Reflection.vsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
因此,它看起来像“Shader.vsh”是一种叫做“资源“和”Reflection.vsh“在”源“中。我认为这是问题的一部分。但是(a)这甚至意味着什么,以及(b)我应该如何解决它?在文本编辑器中编辑project.pbxproj是否安全?
太棒了!出于好奇,我尝试在emacs中编辑project.pbxproj,并将着色器从“Sources”移动到“Resources”中,实际上它工作正常。但是很高兴知道在Xcode中有一个合适的方法可以做到这一点......下次我肯定会这样做。非常感谢! – otherthings