DirectFB なるものの存在を今更知ったので動くか確認してみました。(ほんとに今更・・・)
必要なもののインストール
$ sudo apt-get install libdirectfb-extra
$ sudo apt-get install libdirectfb-dev
$ sudo apt-get install libdirectfb-bin
設定
.directfbrc という設定ファイルに以下の内容を記述します. こうしないとエラーが起こってしまいました。
こうしておくと X11 の上で動作させることが出来ました。
system=x11
fbdev=/dev/fb0
no-vt
mode=800x600
primary-only
サンプルコード
StackOverflow かどこかで公開されていたコードを試してみました。
#include
#include
#include
#include
using namespace std;
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 ); \
} \
}
int main(int argc, char **argv) {
DFBSurfaceDescription dsc;
DFBCHECK(DirectFBInit (&argc, &argv));
DFBCHECK(DirectFBCreate (&dfb));
DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
dsc.flags = DSDESC_CAPS;
dsc.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_FLIPPING);
DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));
DFBCHECK(primary->GetSize (primary, &screen_width, &screen_height));
DFBCHECK(primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
DFBCHECK(primary->SetColor (primary, 0xFF, 0xFF, 0x00, 0xff));
DFBCHECK(primary->SetSrcColorKey(primary, 0xFF, 0xFF, 0x00));
DFBCHECK(primary->SetBlittingFlags(primary, (DFBSurfaceBlittingFlags) ( DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_SRC_COLORKEY)));
DFBCHECK(primary->DrawLine (primary, 0, screen_height / 2, screen_width - 1, screen_height / 2));
primary->Flip(primary, NULL, DFBSurfaceFlipFlags(0));
sleep(3);
primary->Release(primary);
dfb->Release(dfb);
cout << "DONE!\n";
return 0;
}
コンパイルは、以下のようにしました。
$ g++ test.cpp -o test -I/usr/include/directfb -ldirectfb
動作結果
実行すると別窓が開いて以下のようになりました。またコンソール側にもログが出てくるようです。
~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.2.10 |~~~~~~~~~~~~~~~~~~~~~~~~~~
(c) 2001-2008 The world wide DirectFB Open Source Community
(c) 2000-2004 Convergence (integrated media) GmbH
----------------------------------------------------------------
(*) DirectFB/Core: Single Application Core. (2014-10-24 12:33)
(*) Direct/Memcpy: Using Generic 64bit memcpy()
(*) Direct/Thread: Started 'X11 Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
(*) DirectFB/Input: X11 Input 0.1 (directfb.org)
(*) DirectFB/Genefx: MMX detected and enabled
(*) DirectFB/Graphics: MMX Software Rasterizer 0.6 (directfb.org)
(*) DirectFB/Core/WM: Default 0.3 (directfb.org)
(*) X11/Window: Creating 800x 600 RGB32 window...
(*) X11/Display: Using XShm.
(*) X11/Window: Creating 800x 600 RGB32 window...
(*) X11/Display: Using XShm.
(*) X11/Window: Creating 800x 600 RGB32 window...
(*) X11/Display: Using XShm.
DONE!