转自:http://blog.csdn.net/xyyangkun/article/details/8528941
之前用点陈字库做过3515,3520a的字库,现在为新需求,要用矢量字库做osd。决定用SDL_tff库做。
配置freetype:
xy@xy-pc:~/aaa/freetype-2.4.10$ CC=arm-hisiv200-linux-gcc ./configure --prefix=/home/xy/aaa/bin --host=arm-linux
(--prefix 指定编译后,相关库文件存放的路径;)
编译安装:make ,make install。
配置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
编译安装。
配置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
编译安装.
[cpp]
view plain
copy
-
-
-
-
-
-
- #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
",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
",
- "ptsize", 18, SDL_GetError());
- }
-
-
-
-
-
-
-
- SDL_Color forecol= { 0x00, 0x00, 0x00, 0 };
- char *string="你好啊";
- text = TTF_RenderUTF8_Solid(font, string, forecol);
-
-
-
- SDL_SaveBMP(text, "1.bmp");
-
-
-
-
- SDL_FreeSurface(text);
- TTF_CloseFont(font);
- TTF_Quit();
-
- }
就可以保存成1.bmp了。输入了汉字。代码保存的文本格式应该utf-8.
对于海思3520a用的是rgb1555格式,所以应该转成那种格式:
[cpp]
view plain
copy
-
- 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 16 bpp");
- 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);
添加以上代码,基本就可以达到了。
因为自己的不细心,调试了大半天。真是不应该啊。其实早知道这样做,但是思维上总是背道而驰。
以后编程应该更细心,至少节省时间啊。。。。