[英]GLKTextureLoader with texture not in mainBundle
我正在使用GLKit使用OpenGL ES 2.0開發iPhone應用程序。 我正在使用GLKTextureLoader加載紋理。 當我的紋理放在mainBundle內部時, 一切都很好。 我通過命令[[NSBundle mainBundle] pathForResource:@"brushRose.png" ofType:nil]
獲得名稱,紋理具有以下路徑:
/var/mobile/Containers/Bundle/Application/D79492CB-D03C-464D-B06E-00D0DE4389DF/Texture Test.app/brushRose.png
當我嘗試從Internet下載絕對相同的紋理並將其存儲在Application的Documents
文件夾中時。 路徑如下:
/var/mobile/Containers/Data/Application/CD3FBAAB-B8AE-47F5-9C6E-51C854FC1620/Documents/brushes/ps_roses.png
我得到一個可怕的最終結果 ,可以在下圖觀察到: 第一行-來自mainBundle的紋理,第二行-來自文檔
歡迎提出解決第二種情況的任何想法。
測試項目可以在這里找到
當您構建包含PNG的應用程序時,Xcode會對它們運行pngcrush
,除其他外,它會預乘alpha 。
您使用的“非主捆綁”文件沒有預乘Alpha。 這解釋了外觀上的差異。
您可以選擇在網址紋理上運行pngcrush
,或者停止pngcrush在您的項目中運行,或者在加載未GLKTextureLoaderApplyPremultiplication
PNG時有條件地應用GLKTextureLoaderApplyPremultiplication
:
NSMutableDictionary *options = [@{ GLKTextureLoaderOriginBottomLeft : @NO} mutableCopy];
if ( /** png is uncrushed **/ ) {
options[GLKTextureLoaderApplyPremultiplication] = @YES;
}
NSError* error;
GLKTextureInfo* texture = [GLKTextureLoader textureWithContentsOfFile:brushPath options:options error:&error];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.