海思osd+freetype+SDL+SDL_ttf字体

网上相关功能实现资料有很多,关键操作:海思osd+freetype+SDL+SDL_ttf字体颜色。我的虚拟机是 Ubuntu 14.04,那首先移植 freetype+SDL+SDL_ttf 这三个库。 编译安装后哦 生成文件在 /usr/local/include,lib.share,bin 四个目录中
一、库移植
(1)freetype下载安装
1、下载

freetype下载
选择下载版本为: freetype-2.4.10.tar.gz

2、安装

解压: # 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
(2)SDL下载安装
1、下载

SDL下载
选择下载版本:SDL-1.2.15.tar.gz

2、安装

解压: # 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
(3)SDL_ttf下载安装
1、下载

SDL_ttf下载
选择下载版本:SDL_ttf-2.0.11.tar.gz

2、安装

解压: # 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!!
二、测试
(1)拷贝生成sdl库

mkdir /opt/sdl_lib
cd /opt/sdl_lib
cp /usr/local/include/ ./ -rf
cp /usr/local/lib/ ./ -rf
(2)编写测试程序

/************************************************************

File Name: test.c
Author: Sues
Mail: [email protected]
Created Time: 2017年02月28日 星期二 21时47分05秒
************************************************************/

#include<stdio.h>
#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;
}

(3)编译

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

猜你喜欢

转载自blog.csdn.net/whereisdog/article/details/82769222
SDL