2013-06-05 59 views
1

我試圖自己教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是否安全?

回答

3

你幾乎已經知道了--xcode需要知道這些是需要複製的資源,而不是源代碼。無需手工編輯項目文件,很容易在Xcode修復:

  • 選擇您的項目(從左邊的列)
  • 選擇目標
  • 選擇構建階段選項卡
  • 如果着色器出現在「編譯源代碼」,將其刪除
  • 添加着色器「複製捆綁資源」

這就是它!請記住,您必須爲添加的每個新着色器執行此操作。

+0

太棒了!出於好奇,我嘗試在emacs中編輯project.pbxproj,並將着色器從「Sources」移動到「Resources」中,實際上它工作正常。但是很高興知道在Xcode中有一個合適的方法可以做到這一點......下次我肯定會這樣做。非常感謝! – otherthings

相關問題