Try this:
*primary_surface->SetBlittingFlags(primary_surface,
DSBLIT_BLEND_ALPHACHANNEL);*

You might have to remove the calls to SetSrcBlendFunction() and
SetDstBlendFunction().

[]'s

On Thu, Nov 18, 2010 at 5:22 AM, Kelvin Chen <ryu...@gmail.com> wrote:

> Hi, all:
>
> How can I make IDirectFBSurface::blit supporting a transparent background?
> I have tried a lot of methods, but it doesn't work.
>
> Here is my problem.
> 1> draw something to the primary_surface
> 2> create a tempory_surface with transparent background and draw something
> to it
> 3> blit the content of temporary_surface to the pramary_surface, but this
> operation should not erase what primary_surface already have
>
> Here is my code, it doesn't work, I don't know why. The blue rectangle draw
> on the primary_surface will be erased after the blit operation.
>
> Thanks a lot!
>
> #include <iostream>
> #include <directfb.h>
> *using* *namespace* std;
>
> *int* main(*int* argc, *char* *argv[])
> {
>     IDirectFB *dfb;
>
>     // Initialize DirectFB
>     DirectFBInit(&argc, &argv);
>     DirectFBCreate(&dfb);
>     dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);
>
>
>     // Create primary surface
>     IDirectFBSurface *primary_surface;
>     DFBSurfaceDescription primary_surface_description;
>     primary_surface_description.flags = 
> DFBSurfaceDescriptionFlags(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | 
> DSDESC_PIXELFORMAT);
>
>     primary_surface_description.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY 
> | DSCAPS_FLIPPING);
>     primary_surface_description.pixelformat = DSPF_ARGB;
>     primary_surface_description.width = 1280;
>     primary_surface_description.height = 800;
>
>     dfb->CreateSurface(dfb, &primary_surface_description, &primary_surface);
>     // Draw a big blue square
>     primary_surface->SetColor(primary_surface, 0x00, 0x00, 0xff, 0xff);
>
>     primary_surface->FillRectangle(primary_surface, 50, 50, 600, 600);
>     primary_surface->Flip(primary_surface, NULL, DFBSurfaceFlipFlags(0));
>     // Sleep 1 seconds to observe the result
>
>     sleep(1);
>
>     // Create temporary surface
>     IDirectFBSurface *temporary_surface;
>     DFBSurfaceDescription temporary_surface_description;
>     temporary_surface_description.flags = 
> DFBSurfaceDescriptionFlags(DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | 
> DSDESC_PIXELFORMAT);
>
>     temporary_surface_description.caps = 
> DFBSurfaceCapabilities(DSCAPS_FLIPPING); // Not primary
>     temporary_surface_description.pixelformat = DSPF_ARGB;
>     temporary_surface_description.width = 1280;
>
>     temporary_surface_description.height = 800;
>     dfb->CreateSurface(dfb, &temporary_surface_description, 
> &temporary_surface);
>     // Clear the background with transparent black
>
>     temporary_surface->Clear(temporary_surface, 0, 0, 0, 0);
>     temporary_surface->SetColor(temporary_surface, 0, 0, 0, 0);
>     temporary_surface->FillRectangle(temporary_surface, 0, 0, 1280, 800);
>
>     // Draw a small red square
>     temporary_surface->SetColor(temporary_surface, 0xff, 0x00, 0x00, 0xff);
>     temporary_surface->FillRectangle(temporary_surface, 0, 0, 200, 200);
>
>     temporary_surface->Flip(temporary_surface, NULL, DFBSurfaceFlipFlags(0));
>     // Copy the content of the temporary surface to primary surface
>     DFBRectangle rect;
>     rect.x = 0;
>
>     rect.y = 0;
>     rect.w = 1280;
>     rect.h = 800;
>     temporary_surface->SetSrcBlendFunction(temporary_surface, DSBF_SRCALPHA);
>     primary_surface->SetDstBlendFunction(primary_surface, DSBF_DESTALPHA);
>
>     primary_surface->Blit(primary_surface, temporary_surface, &rect, 0, 0);
>     primary_surface->Flip(primary_surface, NULL, DFBSurfaceFlipFlags(0));
>     // Sleep 3 seconds to observe the result
>
>     // Note that the original blue square is not destroyed
>     sleep(3);
>
>     temporary_surface->Release(temporary_surface);
>     primary_surface->Release(primary_surface);
>
>     dfb->Release(dfb);
>
>     *return* 0;
> }
>
>
>
>
> --
> Kelvin Chen
>
> _______________________________________________
> directfb-users mailing list
> directfb-users@directfb.org
> http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users
>
>
_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to