博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
directfb显示中文
阅读量:2426 次
发布时间:2019-05-10

本文共 4797 字,大约阅读时间需要 15 分钟。

原文:http://www.cnblogs.com/cornsea/archive/2009/09/15/1567365.html

  1. 编译directfb软件栈

     需要的软件包:
       zlib_1.2.3.3.dfsg.orig.tar.gz, libpng-1.2.38.tar.bz2 , jpegsrc.v7.tar.gz,
      freetype_2.3.7.orig.tar.gz,  directfb_1.2.8.orig.tar.gz
     (1) zlib 编译:
                 tar zxvf ../src/zlib_1.2.3.3.dfsg.orig.tar.gz
                 cd zlib-1.2.3.3.dfsg
                 CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/opt
                 make && make install
                 cd .. && rm -rf zlib*
     (2) libpng  编译:
tar jxvf ../src/libpng-1.2.38.tar.bz2
cd libpng-1.2.38/
PKG_CONFIG_PATH=/opt/lib/
pkgconfig CC=arm-none-linux-gnueabi-gcc CFLAGS=-I/opt/include  \
LDFLAGS=-L/opt/lib ./configure --host=arm-none-linux-gnueabi --prefix=/opt --with-gnu-ld
make && make install
cd .. && rm -rf libpng*
     (3) libjpeg 编译:
                  tar zxvf ../src/jpegsrc.v7.tar.gz
                 cd jpeg-7/
                 CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-none-linux-gnueabi \
                 --prefix=/opt --with-gnu-ld
                make && make install
                 cd .. && rm -rf jpeg*
       (4) freetype 编译:
             tar zxvf ../src/freetype_2.3.7.orig.
tar.gz
             cd freetype-2.3.7/
             PKG_CONFIG_PATH=/opt/lib/
pkgconfig CC=arm-none-linux-gnueabi-gcc \
             CFLAGS=-I/opt/include LDFLAGS=-L/opt/lib ./configure --host=arm-none-linux-gnueabi  \
             --prefix=/opt --with-gnu-ld
            make && make install
             cd .. && rm -rf freetype*
        (5) directfb 编译:
tar zxvf ../src/directfb_1.2.8.orig.
tar.gz
cd directfb-1.2.8
CPPFLAGS="-I/opt/include" CFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" \
PKG_CONFIG_PATH="/opt/lib/
pkgconfig" CC=arm-none-linux-gnueabi-gcc \
./configure --host=arm-none-linux-gnueabi --prefix=/opt --exec-prefix=/opt --enable-zlib --disable-x11  \
--enable-fbdev --disable-sdl --disable-vnc --enable-jpeg --disable-gif \
--enable-text --enable-freetype --enable-text --disable-network --disable-debug-support \
--disable-video4linux --with-gnu-ld
make && make install
cd .. && rm -rf directfb*
 2. 配置根文件系统
     (1) 复制库文件(可根据需要选择,比如帮助文件之类的可以不要, 还可以strip,减少库的占用空间) 
          cp -avrf /opt/*  /mnt/armfs/opt/
     (2) 复制字体文件
          cp -avf /usr/share/fonts/truetype/wqy/
wqy-zenhei.ttc  /mnt/armfs/opt/share/directfb-
1.2.8/
 3. 编译可应用程序 (参考directfb的文本显示例子)
     程序代码(我用的是linux系统,
所以源代码中输入的中文应该是utf8的):
/**
 * text.c
 *
 * Drawing text
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <directfb.h>
/*
 * (Globals)
 */
static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static int screen_width  = 0;
static int screen_height = 0;
#define DFBCHECK(x...)                
                         \
  {                             
                               \
    DFBResult err = x;                            
             \
                              
                              
   \
    if (err != DFB_OK)                       
                  \
      {                             
                           \
        fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
        DirectFBErrorFatal( #x, err );                         \
      }                             
                           \
  }
/*
 * The font we will use to draw the text.
 */
static IDirectFBFont *font = NULL;
/*
 * The string we will draw. Strings in DirectFB have to UTF-8 encoded.
 * For ASCII characters this does not make any difference.
 */
static char *text = "DirectFB rulez!我是中国人";
#define DATADIR "/opt/share/directfb-1.2.8"
int main (int argc, char **argv)
{
  int i, width;
  /*
   * A structure describing font properties.
   */
  DFBFontDescription font_dsc;
  /*
   * (Locals)
   */
  DFBSurfaceDescription dsc;
  /*
   * (Initialize)
   */
  DFBCHECK (DirectFBInit (&argc, &argv));
  DFBCHECK (DirectFBCreate (&dfb));
  DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
  dsc.flags = DSDESC_CAPS;
  dsc.caps  = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
  DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
  DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
  /*
   * First we need to create a font interface by passing a filename
   * and a font description to specify the desired font size. DirectFB will
   * find (or not) a suitable font loader.
   */
  font_dsc.flags = DFDESC_HEIGHT;
  font_dsc.height = 48;
  DFBCHECK (dfb->CreateFont (dfb, DATADIR"/wqy-zenhei.ttc", &font_dsc, &font));
 
  /*
   * Set the font to the surface we want to draw to.
   */
  DFBCHECK (primary->SetFont (primary, font));
 
  /*
   * Determine the size of our string when drawn using the loaded font.
   * Since we are interested in the full string, we pass -1 as string length.
   */
  DFBCHECK (font->GetStringWidth (font, text, -1, &width));
  /*
   * We want to let the text slide in on the right and slide out on the left.
   */
  for (i = screen_width; i > -width; i--)
    {
      /*
       * Clear the screen.     
       */
      DFBCHECK (primary->SetColor (primary, 0x0, 0x0, 0x0, 0xFF));
      DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
      /*
       * Set the color that will be used to draw the text.
       */
      DFBCHECK (primary->SetColor (primary, 0x80, 0x0, 0x20, 0xFF));
      /*
       * Draw the text left aligned with "i" as the X coordinate.
       */
      DFBCHECK (primary->DrawString (primary, text, -1, i, screen_height / 2, DSTF_LEFT));
      /*
       * Flip the front and back buffer, but wait for the vertical retrace to avoid tearing.
       */
      DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
    }
  /*
   * Release the font.
   */
  font->Release (font);
  /*
   * (Release)
   */
  primary->Release (primary);
  dfb->Release (dfb);
 
  return 23;
}
你可能感兴趣的文章
基于深度学习实现语义识别和问答判断模型及算法优化-制造业-CSDN公开课-专题视频课程...
查看>>
AWS 在线公开课(大数据及分析):Amazon Kinesis和Spark流式处理-CSDN公开课-专题视频课程...
查看>>
引领微服务创新-IBM Microservice Builder 新技术首播!-CSDN公开课-专题视频课程
查看>>
移动平台增强现实体验编辑器 PTC ThingWorx Studio入门-CSDN公开课-专题视频课程
查看>>
深度学习入门及如何转型AI领域-CSDN公开课-专题视频课程
查看>>
基于骁龙 VR SDK的VR图形优化-CSDN公开课-专题视频课程
查看>>
让机器读懂你的意图——人体行为预测入门-CSDN公开课-专题视频课程
查看>>
应用Bluemix实现商业价值-CSDN公开课-专题视频课程
查看>>
传统IT环境与PaaS环境下的应用开发模式-CSDN公开课-专题视频课程
查看>>
SDCC 2017之大数据技术实战线上峰会-CSDN公开课-专题视频课程
查看>>
一个CloudCC生态软件包的诞生:带你体验CloudCC生态-CSDN公开课-专题视频课程
查看>>
极简运维,无限扩容——Serverless Monitoring技术公开课-CSDN公开课-专题视频课程...
查看>>
常用Android程序逆向与保护技术-CSDN公开课-专题视频课程
查看>>
【Python系列之】Python Django 框架初次体验-CSDN公开课-专题视频课程
查看>>
Hadoop 3.0 新特性原理及架构分析-CSDN公开课-专题视频课程
查看>>
3小时掌握数据挖掘-CSDN公开课-专题视频课程
查看>>
Web 全栈全端技术体系与软件四层结构-CSDN公开课-专题视频课程
查看>>
AI学习挑战直播课:成功案例分享及行业趋势分析-CSDN公开课-专题视频课程
查看>>
【UI/UE设计师】banner设计原则-CSDN公开课-专题视频课程
查看>>
大数据智能:金融行业用户画像实践教程-CSDN公开课-专题视频课程
查看>>