從網上下了個blobsallad(點擊開啟連結)的代碼,很有趣,準備移植到iOS平台上。
程式需要Cairo,SDL,首先編譯這他們的iOS平台庫。
SDL 1.3天然支援iOS的編譯,不在話下。
編譯Cairo:
Cairo又依賴libpng,pixman,下載這兩個庫的原始碼。
模擬器編譯安裝 libpng pixman
./configure CC="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -std=c99 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/" AR="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar"
一切順利,但是不適用於Cairo的編譯,於是,一遍一遍的試,關掉了N多特性後,編譯成功:
./configure CC="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -std=gnu99 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/ -miphoneos-version-min=5.0" AR="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar"
--enable-xlib=no --enable-xlib-xrender=no --enable-ft=no --enable-script=no --enable-ps=no --enable-pdf=no --enable-svg=no --enable-trace=no --enable-interpreter=no --enable-png=no
真機編譯:
armv6:
./configure --host=arm-apple-darwin10 CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=gnu99 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk"
./configure --host=arm-apple-darwin10 CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=gnu99 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/" --enable-xlib=no --enable-xlib-xrender=no
--enable-ft=no --enable-script=no --enable-ps=no --enable-pdf=no --enable-svg=no --enable-trace=no --enable-interpreter=no --enable-png=no
armv7:
./configure --host=arm-apple-darwin10 CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=gnu99 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk"
./configure --host=arm-apple-darwin10 CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -std=gnu99 -arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/" --enable-xlib=no --enable-xlib-xrender=no
--enable-ft=no --enable-script=no --enable-ps=no --enable-pdf=no --enable-svg=no --enable-trace=no --enable-interpreter=no --enable-png=no
建立iOS工程。
把編譯好的cairo.a,sdl.a,pixman.a拖到工程裡。
添加幾個framework: audiotoolbox, audiocore, quartzcore, opengles
第一次編譯代碼,出錯。
原因是blob用的SDL 1.2,一些API在1.3上有修改。
現學現用,根據API名字猜功能,做了些改動,可以運行,但可能方法不規範,麻煩請指正。
1.3不在支援surface的直接繪製,而是採用windows,render控制。
surface和render之間也沒找到直接的聯絡,於是就用了texture這個間接聯絡。
1.在bs_cairo.c裡面,建立screen,修改為:
SDL_Window *window = SDL_CreateWindow(NULL, 0, 0, width, height, SDL_WINDOW_SHOWN); pCairoSdl->pRender = SDL_CreateRenderer(window, -1, 0); if (pCairoSdl->pRender == NULL) { fprintf(stderr, "SDL_CreateSoftwareRenderer failed: %s\n", SDL_GetError()); exit(1); } pCairoSdl->pScreen = SDL_CreateRGBSurface (SDL_SWSURFACE, width, height, 32, 0,0,0,0); if(pCairoSdl->pScreen == NULL) { fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError()); exit(1); } pCairoSdl->pTexture = SDL_CreateTextureFromSurface(pCairoSdl->pRender, pCairoSdl->pScreen); if(pCairoSdl->pTexture == NULL) { fprintf(stderr, "SDL_CreateTextureFromSurface failed: %s\n", SDL_GetError()); exit(1); }
2.bs_main繪製:
SDL_DestroyTexture(pMainData->pCairoSdl->pTexture); pMainData->pCairoSdl->pTexture = SDL_CreateTextureFromSurface( pMainData->pCairoSdl->pRender, pMainData->pCairoSdl->pScreen); SDL_RenderCopy(pMainData->pCairoSdl->pRender, pMainData->pCairoSdl->pTexture, &srcRect, &dstRect); SDL_RenderPresent(pMainData->pCairoSdl->pRender);
大功告成: