如需转载请注明出处:https://blog.csdn.net/qq_29350001/article/details/79075800
网上相关功能实现资料有很多,关键操作:海思osd+freetype+SDL+SDL_ttf字体颜色。我的虚拟机是 Ubuntu 14.04,那首先移植 freetype+SDL+SDL_ttf 这三个库。
解压: # tar -xvf freetype-2.4.10.tar.gz
进入freetype文件目录: # cd freetype-2.4.10
执行: # ./configure CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux
编译:make && make install
解压: # tar -xvf SDL-1.2.15.tar.gz
进入SDL文件目录: # cd SDL-1.2.15/
执行: # ./configure CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux
编译:make && make install
解压: # tar -xvf SDL_ttf-2.0.11.tar.gz
进入SDL_ttf文件目录: # cd SDL_ttf-2.0.11/
执行: # ./configure CC=arm-hisiv300-linux-gcc --host=arm-hisiv300-linux --with-freetype-prefix=/usr/local/ --with-sdl-prefix=/usr/local/
编译: make && make install
注意:将上面的 – 改为两个 -
这是CSDN编译器的bug!!
mkdir /opt/sdl_lib
cd /opt/sdl_lib
cp /usr/local/include/ ./ -rf
cp /usr/local/lib/ ./ -rf
/************************************************************
> File Name: test.c
> Author: Sues
> Mail: [email protected]
> Created Time: 2017年02月28日 星期二 21时47分05秒
************************************************************/
#include
#include "SDL.h"
#include "SDL_ttf.h"
int main(int argc, const char *argv[])
{
char * pstr = "hello";
SDL_PixelFormat *fmt;
TTF_Font *font;
SDL_Surface *text, *temp;
if (TTF_Init() < 0 )
{
fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
SDL_Quit();
}
font = TTF_OpenFont("./simhei.ttf", 48);
if ( font == NULL )
{
fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",18,"ptsize", SDL_GetError());
}
SDL_Color forecol = { 0xff, 0xff, 0xff, 0xff };
text = TTF_RenderUTF8_Solid(font, pstr, forecol);
fmt = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat));
memset(fmt,0,sizeof(SDL_PixelFormat));
fmt->BitsPerPixel = 16;
fmt->BytesPerPixel = 2;
fmt->colorkey = 0xffffffff;
fmt->alpha = 0xff;
temp = SDL_ConvertSurface(text,fmt,0);
SDL_SaveBMP(temp, "save.bmp");
SDL_FreeSurface(text);
SDL_FreeSurface(temp);
TTF_CloseFont(font);
TTF_Quit();
return 0;
}
# arm-hisiv300-linux-gcc test.c `sdl-config --cflags --libs` -I/opt/sdl_lib/include -I/opt/sdl_lib/include/SDL -L/opt/sdl_lib/lib -lSDL -lSDL_ttf -Wl,-rpath -o test
想了解更多,参看:UNIX再学习 – 静态库与共享库
模组烧写,参看:Hi3516A开发-- 生成烧写最小文件系统 squashfs
在test文件下放置simhei.ttf文件,这样才能找到字体
如需转载请注明出处:https://blog.csdn.net/qq_29350001/article/details/79075800