Cairo,SDL在iOS平台的編譯,運行

來源:互聯網
上載者:User

從網上下了個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);

大功告成:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.