DirectFB 與範例的原始碼可從 DirectFB.org 下載到 /home/ 目錄。整體流程如下。
tar -xzf DirectFB-1.3.0.tar.gz tar -xzf DirectFB-examples-1.2.0.tar.gz
cd DirectFB-1.3.0 ./configure make make install
若 ./configure 出現下列提示:
PNG support is missing - many applications won't work correctly! JPEG support is missing - many applications won't work correctly! FreeType2 support is missing - many applications won't work correctly!
用 apt-cache 搜尋並安裝對應的開發套件即可:
apt-cache search libpng apt-cache search libjpeg apt-cache search libfreetype apt-get install libpng3-dev 等
a. 先啟用 framebuffer,編輯 /boot/grub/menu.lst,在 kernel 行尾加上 vga=0x0317(1024×768)或 vga=788(800×600):
#****************start*************# title Ubuntu, kernel 2.6.17-10-generic root (hd0,6) kernel /vmlinuz-2.6.17-10-generic root=/dev/sda8 ro quiet splash locale=zh_CN vga=0x0317 initrd /initrd.img-2.6.17-10-generic quiet savedefault boot #****************stop**************#
b. 更新資料庫並找出 pkgconfig 路徑:
updatedb locate directfb.pc
c. 設定環境變數:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
這只在當前終端有效。若要永久生效,root 使用者可在 /root/.profile 中加入:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
d. 編譯安裝:
make make install
e. 指定函式庫路徑,在 /etc/ld.so.conf 最後一行加入 /usr/local/lib,存檔後執行:
ldconfig
f. 重新開機。若省略這步,可能出現下列錯誤:
(*) DirectFB/Core: Single Application Core. (2007-10-22 15:48) (!) Direct/Util: opening '/dev/fb0' failed --> No such device (!) DirectFB/FBDev: Error opening framebuffer device! (!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable. (!) DirectFB/Core: Could not initialize 'system_core' core! --> Initialization error!
cd DirectFB-examples-1.3.0/src/ ./df_andi
看到畫面就代表安裝完成。
若不想讓程式全螢幕、想改用 SDL 而非 fbdev 引擎,可建立並修改 /etc/directfbrc。
7.10 預設屏蔽了 framebuffer 模組,所以 GRUB 參數加 vga=xxx 沒用。解法是:
1. 編輯 /etc/initramfs-tools/modules,加入三行:
fbcon vesafb vga16fb
2. 最關鍵的一步:把 /etc/modprobe.d/blacklist-framebuffer 裡的 vesafb 與 vga16fb 兩行註解掉。
3. 用 hwinfo 查顯卡支援的 vga 值:
sudo hwinfo --framebuffer
輸出會列出可用模式,例如:
Mode 0x0305: 1024x768 (+1024), 8 bits Mode 0x0317: 1024x768 (+2048), 16 bits Mode 0x0318: 1024x768 (+4096), 24 bits Mode 0x0312: 640x480 (+2560), 24 bits Mode 0x0314: 800x600 (+1600), 16 bits
我在 kernel 後加了 vga=0x0317,也就是 1024×768 的 16 位色。
4. 最後刷新 initramfs 並重開:
sudo update-initramfs -u