从网上下了个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);
}
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);