Hello all,
I'm a newbie in DirectFB and trying to load a png file with a transparent
background, to do this I created a temporary surface srfc, then I load the
png file using CreateImageProvider() in this surface, I Blit it in surface
get from window and Flip()-it on screen but the image on screen has always a
black background (or other color according the color on Clear() command when
creating surface), My doubt is how to Blit() this image on the window
surface showing the correct transparent background ? I believe the problem
is configuring the alpha blending parameters when creating the surfaces but
I can't understand what the correct parameters.
Follows the code where I doing my experiments.
Thanks for all help
Flavio Alberto Lopes Soares
#include <stdio.h>
#include <unistd.h>
#include <directfb.h>
#define DATADIR "/home/flavio/workspace/figuras/volume"
IDirectFB *dfb = NULL;
IDirectFBDisplayLayer *layer = NULL;
IDirectFBWindow *window = NULL;
IDirectFBSurface *wsurface = NULL;
IDirectFBSurface *srfc = NULL;
DFBSurfaceDescription dsc;
DFBGraphicsDeviceDescription gdesc;
DFBWindowDescription wind_desc;
DFBWindowOptions woptions;
IDirectFBImageProvider *imgprovider;
int main(int argc, char *argv[])
{
if( DirectFBInit(NULL,NULL) != DFB_OK )
fprintf(stderr, "Cannot init DirectFB.\n");
else {
if( DirectFBCreate( &dfb ) != DFB_OK )
fprintf(stderr, "Cannot create DFB super interface.\n");
else {
dfb->SetCooperativeLevel(dfb, DFSCL_NORMAL);
dfb->GetDisplayLayer (dfb, DLID_PRIMARY, &layer);
dfb->GetDeviceDescription( dfb, &gdesc );
if ( !((gdesc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
(gdesc.blitting_flags & DSBLIT_BLEND_COLORALPHA )) ) {
DFBDisplayLayerConfig layer_config;
layer_config.flags = DLCONF_BUFFERMODE;
layer_config.buffermode = DLBM_BACKVIDEO;
layer->SetConfiguration( layer, &layer_config );
}
dsc.flags = DSDESC_CAPS;
dsc.caps = (DFBSurfaceCapabilities) (DSCAPS_SUBSURFACE |
DSCAPS_VIDEOONLY | DSCAPS_PREMULTIPLIED | DSCAPS_FLIPPING);
dsc.pixelformat = DSPF_ARGB;
dsc.width = 125;
dsc.height = 125;
dfb->CreateSurface( dfb, &dsc, &srfc );
srfc->SetBlittingFlags(srfc, DSBLIT_BLEND_ALPHACHANNEL);
srfc->SetPorterDuff( srfc, DSPD_ADD );
srfc->SetDstBlendFunction(srfc, DSBF_SRCALPHA);
srfc->SetDrawingFlags(srfc, DSDRAW_BLEND);
srfc->Blit(srfc, srfc, NULL, 0, 0);
srfc->Flip (srfc, NULL, DSFLIP_ONSYNC);
//window attributes
wind_desc.flags = (DFBWindowDescriptionFlags) (DWDESC_POSX |
DWDESC_POSY | DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_CAPS);
wind_desc.caps = (DFBWindowCapabilities) (DWCAPS_ALPHACHANNEL
| DWCAPS_NODECORATION);
wind_desc.stacking = DWSC_UPPER;
wind_desc.posx = 100;
wind_desc.posy = 100;
wind_desc.width = 250;
wind_desc.height = 250;
layer->CreateWindow(layer, &wind_desc, &window);
//layer->GetWindow(layer, 0, &window);
window->SetOpacity( window, 0xcd );
window->GetOptions (window, &woptions);
window->SetOptions(window,
(DFBWindowOptions)(woptions | \
DWOP_ALPHACHANNEL | \
DWOP_KEEP_ABOVE | \
DWOP_KEEP_SIZE | \
DWOP_KEEP_STACKING | \
DWOP_KEEP_POSITION));
window->GetSurface(window, &wsurface);
wsurface->SetBlittingFlags( wsurface,
DSBLIT_BLEND_ALPHACHANNEL);
wsurface->SetPorterDuff( wsurface, DSPD_ADD );
wsurface->SetDstBlendFunction(wsurface, DSBF_SRCALPHA);
wsurface->SetDrawingFlags(wsurface, DSDRAW_BLEND);
wsurface->Clear(wsurface, 0x00, 0x00, 0x00, 0x00);
wsurface->Flip (wsurface, NULL, DSFLIP_ONSYNC);
DFBRectangle imgpos;
imgpos.x = 60;
imgpos.y = 60;
imgpos.w = 125;
imgpos.h = 125;
dfb->CreateImageProvider(dfb, DATADIR"/volbase.png",
&imgprovider);
imgprovider->RenderTo(imgprovider, srfc, &imgpos);
srfc->Flip(srfc, NULL, DSFLIP_ONSYNC);
wsurface->Blit(wsurface, srfc, &imgpos, 0, 0);
wsurface->Flip(wsurface, NULL, DSFLIP_ONSYNC);
wsurface->SetColor (wsurface, 0xff, 0x00, 0x00, 0xff);
wsurface->DrawRectangle(wsurface, 50, 50, 100, 100);
wsurface->FillRectangle (wsurface, 50, 50, 100, 100);
wsurface->Flip(wsurface, NULL, DSFLIP_ONSYNC);
}
}
while(1)
sleep(1);
}
_______________________________________________
directfb-users mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users