本文共 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; }