Difference between revisions of "How to get started with DirectFB."

From Gumstix User Wiki
Jump to: navigation, search
(correct hello world tutorial)
Line 1: Line 1:
 +
=[http://yxiwisewava.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 
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 7: Line 8:
  
 
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 = "a directfb sample"
+
  DESCRIPTION = "a directfb sample"
  DEPENDS = "directfb"
+
  DEPENDS = "directfb"
  SECTION = "libs"
+
  SECTION = "libs"
  LICENSE = "GPL"
+
  LICENSE = "GPL"
 
   
 
   
  PR = "r0"
+
  PR = "r0"
 
   
 
   
  SRC_URI = " \
+
  SRC_URI = " \
 
   file://dfb.c \
 
   file://dfb.c \
  "
+
  "
 
   
 
   
  S = "${WORKDIR}"
+
  S = "${WORKDIR}"
 
   
 
   
  CFLAGS += "-I/${STAGING_INCDIR}/directfb"
+
  CFLAGS += "-I/${STAGING_INCDIR}/directfb"
 
   
 
   
  LDFLAGS += "-ldirectfb"
+
  LDFLAGS += "-ldirectfb"
 
   
 
   
 
  do_compile () {
 
  do_compile () {
Line 33: Line 34:
 
  }
 
  }
 
   
 
   
  FILES_${PN} = "${bindir}/dfb"
+
  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 <stdio.h>
+
  #include &lt;stdio.h&gt;
  #include <unistd.h>
+
  #include &lt;unistd.h&gt;
  #include <directfb.h>
+
  #include &lt;directfb.h&gt;
 
   
 
   
 
  static IDirectFB *dfb = NULL;
 
  static IDirectFB *dfb = NULL;
Line 50: Line 51:
 
     if (err != DFB_OK)                                        \
 
     if (err != DFB_OK)                                        \
 
       {                                                        \
 
       {                                                        \
         fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
+
         fprintf( stderr, &quot;%s &lt;%d&gt;:\n\t&quot;, __FILE__, __LINE__ ); \
 
         DirectFBErrorFatal( #x, err );                        \
 
         DirectFBErrorFatal( #x, err );                        \
 
       }                                                        \
 
       }                                                        \
Line 59: Line 60:
 
   DFBSurfaceDescription dsc;
 
   DFBSurfaceDescription dsc;
 
   
 
   
   DFBCHECK (DirectFBInit (&argc, &argv));
+
   DFBCHECK (DirectFBInit (&amp;argc, &amp;argv));
   DFBCHECK (DirectFBCreate (&dfb));
+
   DFBCHECK (DirectFBCreate (&amp;dfb));
   DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));   
+
   DFBCHECK (dfb-&gt;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->CreateSurface( dfb, &dsc, &primary ));
+
   DFBCHECK (dfb-&gt;CreateSurface( dfb, &amp;dsc, &amp;primary ));
   DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
+
   DFBCHECK (primary-&gt;GetSize (primary, &amp;screen_width, &amp;screen_height));
   DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
+
   DFBCHECK (primary-&gt;FillRectangle (primary, 0, 0, screen_width, screen_height));
 
   
 
   
   DFBCHECK (primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff));
+
   DFBCHECK (primary-&gt;SetColor (primary, 0x80, 0x80, 0xff, 0xff));
   DFBCHECK (primary->DrawLine (primary,
+
   DFBCHECK (primary-&gt;DrawLine (primary,
 
                        0, screen_height / 2,
 
                        0, screen_height / 2,
 
        screen_width - 1, screen_height / 2));
 
        screen_width - 1, screen_height / 2));
   DFBCHECK (primary->Flip (primary, NULL, 0));
+
   DFBCHECK (primary-&gt;Flip (primary, NULL, 0));
 
   
 
   
 
   sleep (5);
 
   sleep (5);
 
   
 
   
   primary->Release( primary );
+
   primary-&gt;Release( primary );
   dfb->Release( dfb );
+
   dfb-&gt;Release( dfb );
 
   
 
   
 
   return 23;
 
   return 23;

Revision as of 14:44, 23 November 2010

Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly

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.