配置freetype:
xy@xy-pc:~/aaa/freetype-2.4.10$CC=arm-hisiv200-linux-gcc ./configure --prefix=/home/xy/aaa/bin--host=arm-linux编译安装:make ,makeinstall。
配置SDL:
xy@xy-pc:~/aaa/SDL-1.2.15$CC=arm-hisiv200-linux-gcc CXX=arm-hisiv200-linux-cpp ./configure--prefix=/home/xy/aaa/bin --host=arm-linux --disable-alsa--disable-pulseaudio
编译安装。
make
make install
配置SDL_tff:
xy@xy-pc:~/aaa/SDL_ttf-2.0.11$CC=arm-hisiv200-linux-gcc./configure --with-freetype-prefix=/home/xy/aaa/bin--host=arm-linux
编译安装.
- #include
- #include
- #include "SDL/SDL.h"
- #include"SDL/SDL_ttf.h"
- int main(int argc,char**argv)
- {
- TTF_Font *font;
- SDL_Surface *text, *temp;
- if ( TTF_Init() < 0 ){
- fprintf(stderr, "Couldn't initialize TTF:%s\n",SDL_GetError());
- SDL_Quit();
- return(2);
- }
- font = TTF_OpenFont("cu.ttf", 48);
- if ( font == NULL ){
- fprintf(stderr, "Couldn't load %d pt font from %s:%s\n",
- "ptsize", 18,SDL_GetError());
- }
- //TTF_SetFontStyle(font, 0);
- // TTF_SetFontOutline(font, 0);
- //TTF_SetFontKerning(font, 1);
- // TTF_SetFontHinting(font, 0);
- //SDL_Color forecol= { 0xFF, 0xFF, 0xFF, 0};
- SDL_Color forecol= { 0x00, 0x00, 0x00, 0 };
- char*string="你好啊";
- text = TTF_RenderUTF8_Solid(font, string,forecol);
- //SDL_LoadBMP
- SDL_SaveBMP(text, "1.bmp");
- SDL_FreeSurface(text);
- TTF_CloseFont(font);
- TTF_Quit();
- }
就可以保存成1.bmp了。输入了汉字。代码保存的文本格式应该utf-8.
对于海思3520a用的是rgb1555格式,所以应该转成那种格式:
- SDL_Surface *temp =SDL_CreateRGBSurface(SDL_SWSURFACE,
- text->w, text->h, 16,\
- 0x00FF0000, 0x0000FF00, 0x000000FF,
- 0);
- SDL_Rect bounds;
- if (temp !=NULL)
- {
- bounds.x = 0;
- bounds.y = 0;
- bounds.w = text->w;
- bounds.h = text->h;
- if (SDL_LowerBlit(text,&bounds, temp, &bounds) < 0) {
- SDL_FreeSurface(text);
- SDL_SetError("Couldn't convert image to 16bpp");
- text = NULL;
- }
- }
- stBitmap.u32Width = temp->w;
- stBitmap.u32Height = temp->h;
- stBitmap.pData= temp->pixels;
- stBitmap.enPixelFormat= PIXEL_FORMAT_RGB_1555;
- SDL_FreeSurface(text);
- SDL_FreeSurface(temp);
添加以上代码,基本就可以达到了。