Difference between revisions of "How to get started with DirectFB."
Aqisecoxefi (Talk | contribs) |
Searchworks (Talk | contribs) (remove spam) |
||
Line 1: | Line 1: | ||
− | |||
First, what is DirectFB? According to [http://directfb.org http://directfb.org]: | First, what is DirectFB? According to [http://directfb.org http://directfb.org]: | ||
Line 8: | Line 7: | ||
After that is installed you will be ready to make your first program. You should have already done the [http://www.gumstix.net/User-How-To-s/view/Build-system-overview/Hello-world-tutorial/110.html hello world] tutorial. Make a folder in user.collection/packages called dfb. Then make your dfb_1.0.0.bb file and fill it with this. | After that is installed you will be ready to make your first program. You should have already done the [http://www.gumstix.net/User-How-To-s/view/Build-system-overview/Hello-world-tutorial/110.html hello world] tutorial. Make a folder in user.collection/packages called dfb. Then make your dfb_1.0.0.bb file and fill it with this. | ||
− | DESCRIPTION = | + | DESCRIPTION = "a directfb sample" |
− | DEPENDS = | + | DEPENDS = "directfb" |
− | SECTION = | + | SECTION = "libs" |
− | LICENSE = | + | LICENSE = "GPL" |
− | PR = | + | PR = "r0" |
− | SRC_URI = | + | SRC_URI = " \ |
file://dfb.c \ | file://dfb.c \ | ||
− | + | " | |
− | S = | + | S = "${WORKDIR}" |
− | CFLAGS += | + | CFLAGS += "-I/${STAGING_INCDIR}/directfb" |
− | LDFLAGS += | + | LDFLAGS += "-ldirectfb" |
do_compile () { | do_compile () { | ||
Line 34: | Line 33: | ||
} | } | ||
− | FILES_${PN} = | + | FILES_${PN} = "${bindir}/dfb" |
Next make a folder called files and make a file called dfb.c in it. dfb.c should contain | Next make a folder called files and make a file called dfb.c in it. dfb.c should contain | ||
− | #include | + | #include <stdio.h> |
− | #include | + | #include <unistd.h> |
− | #include | + | #include <directfb.h> |
static IDirectFB *dfb = NULL; | static IDirectFB *dfb = NULL; | ||
Line 51: | Line 50: | ||
if (err != DFB_OK) \ | if (err != DFB_OK) \ | ||
{ \ | { \ | ||
− | fprintf( stderr, | + | fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ |
DirectFBErrorFatal( #x, err ); \ | DirectFBErrorFatal( #x, err ); \ | ||
} \ | } \ | ||
Line 60: | Line 59: | ||
DFBSurfaceDescription dsc; | DFBSurfaceDescription dsc; | ||
− | DFBCHECK (DirectFBInit (& | + | DFBCHECK (DirectFBInit (&argc, &argv)); |
− | DFBCHECK (DirectFBCreate (& | + | DFBCHECK (DirectFBCreate (&dfb)); |
− | DFBCHECK (dfb- | + | DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN)); |
dsc.flags = DSDESC_CAPS; | dsc.flags = DSDESC_CAPS; | ||
dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; | dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; | ||
− | DFBCHECK (dfb- | + | DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary )); |
− | DFBCHECK (primary- | + | DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height)); |
− | DFBCHECK (primary- | + | DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height)); |
− | DFBCHECK (primary- | + | DFBCHECK (primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff)); |
− | DFBCHECK (primary- | + | DFBCHECK (primary->DrawLine (primary, |
0, screen_height / 2, | 0, screen_height / 2, | ||
screen_width - 1, screen_height / 2)); | screen_width - 1, screen_height / 2)); | ||
− | DFBCHECK (primary- | + | DFBCHECK (primary->Flip (primary, NULL, 0)); |
sleep (5); | sleep (5); | ||
− | primary- | + | primary->Release( primary ); |
− | dfb- | + | dfb->Release( dfb ); |
return 23; | return 23; |
Latest revision as of 15:25, 23 November 2010
First, what is DirectFB? According to http://directfb.org:
DirectFB is a thin library that provides hardware graphics acceleration, input device handling and abstraction, integrated windowing system with support for translucent windows and multiple display layers, not only on top of the Linux Framebuffer Device. It is a complete hardware abstraction layer with software fallbacks for every graphics operation that is not supported by the underlying hardware. DirectFB adds graphical power to embedded systems and sets a new standard for graphics under Linux.
To write programs that use DirectFB you first have to have it installed. You can either use an image that contains it (gumstix-directfb-image) or you can install it with
ipkg install directfb
After that is installed you will be ready to make your first program. You should have already done the hello world tutorial. Make a folder in user.collection/packages called dfb. Then make your dfb_1.0.0.bb file and fill it with this.
DESCRIPTION = "a directfb sample" DEPENDS = "directfb" SECTION = "libs" LICENSE = "GPL" PR = "r0" SRC_URI = " \ file://dfb.c \ " S = "${WORKDIR}" CFLAGS += "-I/${STAGING_INCDIR}/directfb" LDFLAGS += "-ldirectfb" do_compile () { ${CC} ${CFLAGS} ${LDFLAGS} -o dfb dfb.c } do_install () { install -d ${D}${bindir}/ install -m 0755 ${S}/dfb ${D}${bindir}/ } FILES_${PN} = "${bindir}/dfb"
Next make a folder called files and make a file called dfb.c in it. dfb.c should contain
#include <stdio.h> #include <unistd.h> #include <directfb.h> 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 = 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, 0x80, 0x80, 0xff, 0xff)); DFBCHECK (primary->DrawLine (primary, 0, screen_height / 2, screen_width - 1, screen_height / 2)); DFBCHECK (primary->Flip (primary, NULL, 0)); sleep (5); primary->Release( primary ); dfb->Release( dfb ); return 23; }
This example code came from http://www.directfb.org/docs/DirectFB_Tutorials/simple.html
You should now be ready to compile with
bitbake dfb
then you can install it following the same method in the hello world tutorial.