This tutorial is incomplete and there are a number of issues with it.

If you can enable OpenGL ES acceleration on fb1, please share it.

Running graphical application on an external display consumes more power than usual. If the C.H.I.P crash or reboot when running one of the DirectFB/SDL examples, set the AXP-209 to no limit: sudo axp209 --no-limit

Install general build dependancies:

sudo apt-get install build-essential pkg-config

Install mali driver for OpenGL ES 2.0 acceleration:

sudo apt-get install chip-mali-modules-4.4.13-ntc-mlc chip-mali-userspace

DirectFB

Install dependencies:

sudo apt-get install libpng-dev libjpeg-dev libfreetype6-dev
sudo apt-get install libdrm2 libudev-dev libegl1-mesa-dev libgles1-mesa-dev libgles2-mesa-dev libgbm-dev libgegl-dev libsysfs-dev
sudo apt-get install freeglut3 freeglut3-dev

Latest master branch (1.8.0) with SSD1351 has flickering when running SDL2 demos (from test folder) and the display is black when running its own tests. Use instead the 1.7.6 version. TODO: test version 1.7.7 and 1.6.x.

wget https://github.com/deniskropp/DirectFB/archive/DIRECTFB_1_7_7.tar.gz
tar -zxvf DIRECTFB_1_7_7.tar.gz && cd DirectFB-DIRECTFB_1_7_7/

Configure:

Disable fusion with --disable-multi flag

sh autogen.sh
./configure --with-gfxdrivers='gles2' --enable-static --enable-jpeg --enable-png --enable-zlib --disable-freetype --disable-x11 --enable-wayland=no --disable-idirectfbgl-egl --enable-mesa --disable-egl --disable-egl-united --enable-fbdev --with-inputdrivers=linuxinput --disable-multi --disable-multi-kernel --enable-debug-support --enable-debug --enable-trace

./configure should output that OpenGL ES 2.0 is enabled when finished:

Building Graphics Drivers:
...
--
OpenGL                    no (GLX: no)
OpenGL ES 2.0             yes (Mesa:  yes, PVR2D: no)
                                      -I/usr/include/libdrm  -DGLES2_MESA  -lGLESv2 -lEGL -ldrm -lgbm

IDirectFBGL-EGL           no

If MESA is disabled due to missing packages: *** glesv2 egl libdrm gbm packages not found -- Building without MESA support. You can check which package is not available using pkg-config --libs glesv2

Make & install:

make
sudo make install

Type sudo ldconfig if DirectFB lib is not detected in next steps

Add the mode generated from fbset -fb /dev/fb1 to /etc/fb.modes:

mode "128x128"
    geometry 128 128 128 128 16
    timings 0 0 0 0 0 0 0
    nonstd 1
    rgba 5/11,6/5,5/0,0/0
endmode

Add to directfbrc (/etc/directfbrc or $HOME/.directfbrc):

Prefer /etc/directfbrc as some commands will be executed as root

system=fbdev
fbdev=/dev/fb1
mode=128x128
pixelformat=RGB16
no-linux-input-grab

Test that DirectFB is working properly by running ./dfbtest_fillrect from tests folder. The display should output something similar to this:

directfb test

SDL2

Configure:

wget https://www.libsdl.org/release/SDL2-2.0.5.tar.gz
sh autogen.sh
./configure --disable-video-dummy --disable-video-x11 --disable-video-opengl --enable-video-opengles2 --enable-video-directfb

./configure should output Video drivers : directfb opengl_es2 when finished.

I don't know exactly why, but I had to edit Makefile and remove -Werror=declaration-after-statement from EXTRA_CFLAGS to compile SDL2 with directfb support.

error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement] on some source files located in src/video/directfb/

Make & install:

make
sudo make install

If SDL was compiled with other driver support, you might have to set the video driver explicitly: export SDL_DIRECTFB_X11_CHECK=0 export SDL_VIDEODRIVER=DIRECTFB

You can try some SDL samples like ./testsprite2 from test folder:

testsprite2

Notes:

Test es2_info and es2gears from mesa-utils-extra package and glmark-es2.

Compile cube_vbo with: gcc -Wall -W -o cube_vbo cube_vbo.csdl2-config --libs --cflags-lGL

Try export DISPLAY=:0.0 or export DISPLAY=:0

Resources:

  • https://blog.eldajani.net/banana-pi-arch-linux-accelerated-mali-gpu/
  • http://forum.lemaker.org/thread-12027-1-1.html
  • https://mega-tokyo.com/blog/index.php/site/comments/building_directfb_1.8.0_and_sdl2_for_the_raspberry_pi
  • https://bbs.nextthing.co/t/missing-opengl-es-library/13080/2
  • https://skia.googlesource.com/third_party/sdl/+/master/docs/README-directfb.md