本文主要是介绍移植SDL2_ttf到ARM,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载最新源码,最新的才支持SDL2
然后执行命令,,编译通过,,,,前期准备是要成功安装freetype 和sdl2
./configure --prefix=/gzz/cross_compile/SDL --host=arm-linux --with-sdl-prefix=/gzz/cross_compile/SDL --with-freetype-prefix=/gzz/cross_compile/SDL --with-gnu-ld CPPFLAGS="-I/gzz/cross_compile/SDL/include" LDFLAGS="-L/gzz/cross_compile/SDL/lib"
make ; make install;
测试程序:
#include "SDL.h"
#include<stdio.h>
#include "SDL_ttf.h"
SDL_Window* Main_Window;
SDL_Renderer* Main_Renderer;
int main(int argc,char *argv[]){char *file;int w,h;Uint8 bpp;Uint32 flags;TTF_Font *font; SDL_Color red = {255,0,0};SDL_Color green = {0,255,0};SDL_Surface *message1,*message2;SDL_Texture *Tx_message1,*Tx_message2;SDL_Rect SrcR;SDL_Rect DestR1,DestR2;DestR1.x = 100;DestR1.y = 0;DestR1.h = 50;DestR1.w = 50;DestR2.x = 100;DestR2.y = 50;DestR2.h = 150;DestR2.w = 150;w = 480;h = 272;bpp = 0; flags = SDL_SWSURFACE;if(SDL_Init(SDL_INIT_VIDEO) < 0){fprintf(stderr,"Couldn't initialize SDL:%s\n",SDL_GetError());return (1);}Main_Window= SDL_CreateWindow("ttf test",0,0, w, h, 0);Main_Renderer = SDL_CreateRenderer(Main_Window, -1, SDL_RENDERER_ACCELERATED);if(TTF_Init() == -1)return -1;font = TTF_OpenFont("STZHONGS.TTF",16);if(!font){printf("TTF_OpenFont:Open simsun.ttf %s\n",TTF_GetError());return -1;}message1 = TTF_RenderText_Solid(font, "ttf test", red);message2 = TTF_RenderUTF8_Solid(font, "字体显示", green);Tx_message1 = SDL_CreateTextureFromSurface(Main_Renderer, message1);SDL_FreeSurface(message1); // we got the texture now -> free surfaceTx_message2 = SDL_CreateTextureFromSurface(Main_Renderer, message2);SDL_FreeSurface(message2);
while(1){if(message1||message2){SDL_RenderCopy(Main_Renderer, Tx_message1, NULL, &DestR1);/* render the current animation step of our shape */SDL_RenderCopy(Main_Renderer, Tx_message2, NULL, &DestR2); }
SDL_RenderPresent(Main_Renderer);
}
TTF_CloseFont(font);
SDL_DestroyTexture(Tx_message1);
SDL_DestroyTexture(Tx_message2);
SDL_DestroyRenderer(Main_Renderer);
SDL_DestroyWindow(Main_Window);
SDL_Quit();return 0;
}
这篇关于移植SDL2_ttf到ARM的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!