I've had a look at the tutorial page (link here) and experimented with the first one ( link here)
On looking at the code, the following is required as a template to be used to get a functioning DirectFB program:
#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->SetColor (primary, 0x80, 0x80, 0xff, 0xff));
// Code goes here
DFBCHECK (primary->Flip (primary, NULL, 0));
sleep (1);
primary->Release( primary );
dfb->Release( dfb );
return 23;
}In the above template, where the following appears:
// Code goes hereEnter the code which is required to do what you want to display on screen. I had experimented with drawing lines and rectangles. The code is obtained from the API reference ( link here). On my Ubuntu laptop, version 1.01 is installed, there are API's for new versions.
It has to be noted that the variables screen_width and screen_height are important to the code you put in as this gives the maximum height and width of the screen you use. This is obvious as you can't draw graphics that are bigger than your screen size. I assume that these sizes correlates to the screen resolution you have ie the higher the resolution the higher the variables.
It is not really necessary to understand the ins and outs of how the template works apart from it being the building blocks to get a DirectFB program working. This can be figured out when comfortable with the API.
To compile the program, enter the following command on the terminal (assuming you use Ubuntu which uses pkg-config for ease of compiling):
gcc `pkg-config --cflags directfb` filename.c -o outputname `pkg-config --libs directfb`Where filename.c is name of C file and outputname is the name of compiled program. For example:
gcc `pkg-config --cflags directfb` test.c -o test `pkg-config --libs directfb`It also to be noted that to run the compiled program you have to run it as root. The reason for this is that directFB needs root access to be able to communicate with the framebuffer, keyboard and mouse devices. According to the Readme file (link here) the permissions of these device can be amended so that the directFB program does not need to be run as root.
To run the program, assuming it is called test:
sudo sudo ./testDisplaying text is not as straightforward as a font needs to be defined beforehand. I had some difficulty with this and will require some more investigation.
0 comments:
Post a Comment