![]() | DirectFB Tutorials |
Drawing text |
#include <stdio.h> | |
#include <directfb.h> | |
static IDirectFB *dfb = NULL; |
(Globals) |
static IDirectFBFont *font = NULL; |
The font we will use to draw the text. |
static char *text = "DirectFB rulez!"; |
The string we will draw. Strings in DirectFB have to UTF-8 encoded. For ASCII characters this does not make any difference. |
int main (int argc, char **argv) | |
DFBFontDescription font_dsc; |
A structure describing font properties. |
DFBSurfaceDescription dsc; |
(Locals) |
DFBCHECK (DirectFBInit (&argc, &argv)); |
(Initialize) |
font_dsc.flags = DFDESC_HEIGHT; |
First we need to create a font interface by passing a filename and a font description to specify the desired font size. DirectFB will find (or not) a suitable font loader. |
DFBCHECK (primary->SetFont (primary, font)); |
Set the font to the surface we want to draw to. |
DFBCHECK (font->GetStringWidth (font, text, -1, &width)); |
Determine the size of our string when drawn using the loaded font. Since we are interested in the full string, we pass -1 as string length. |
for (i = screen_width; i > -width; i--) |
We want to let the text slide in on the right and slide out on the left. |
DFBCHECK (primary->SetColor (primary, 0x0, 0x0, 0x0, 0xFF)); |
Clear the screen. |
DFBCHECK (primary->SetColor (primary, 0x80, 0x0, 0x20, 0xFF)); |
Set the color that will be used to draw the text. |
DFBCHECK (primary->DrawString (primary, text, -1, i, screen_height / 2, DSTF_LEFT)); |
Draw the text left aligned with "i" as the X coordinate. |
DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC)); |
Flip the front and back buffer, but wait for the vertical retrace to avoid tearing. |
font->Release (font); |
Release the font. |
primary->Release (primary); |
(Release) |
return 23; |
(C) Copyright by convergence GmbH |
![]() |