移植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 surface
   Tx_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;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值