Hi,

I have an application where I am creating a surface for rendering on the
primary surface.  The problem is that this surface is opaque and I need
to make it globally transparent.  I need to find a method to blit this
opaque surface to the primary surface having a global alpha transparent
value.  This layer needs to be transparent because I am displaying video
on layers 4 or 5.

I cannot seem to make this opaque surface transparent or blend this with
an alpha from the primary surface.

I can easily create this surface with an alpha value and blit it to the
primary surface.  If the surface is transparent it blits over the
primary surface in the manner I am seeking.  However, I cannot seem to
make the surface transparent if it is opaque when created.

I have looked into previous posts for Blending HOWTO and posts on layer
opacity and tired various methods but to no avail.

Thanks in advance for any help you can provide.

Snippet of my example code below.

/* Initialise DirectFB, passing command line options.
 * Options recognised by DirectFB will be stripped. */
DFBCHECK( DirectFBInit(&argc, &argv) );

/* Create the DirectFB root interface. */
DFBCHECK( DirectFBCreate(&pDfb) );

/* Use full screen mode so that a surface has full control of a layer
 * and no windows are created. */
DFBCHECK(pDfb->SetCooperativeLevel(pDfb, DFSCL_FULLSCREEN));

/* Set the surface description - specify which fields are set and set
them. */
surfaceDesc.flags = DSDESC_CAPS;
surfaceDesc.caps  = DSCAPS_PRIMARY | DSCAPS_VIDEOONLY |
DSCAPS_PREMULTIPLIED;

/* Create the frame buffer primary surface by passing our surface
description. */
DFBCHECK( pDfb->CreateSurface(pDfb, &surfaceDesc, &pFrameBuffer) );

/* We now have exclusive access to the frame buffer layer's surface.
 * Obtain the width and height of the frame buffer. */
DFBCHECK(pFrameBuffer->GetSize(pFrameBuffer, &maxWidth, &maxHeight));
    
// Get the Display Interface Layer
DFBCHECK(pDfb->GetDisplayLayer(pDfb, DLID_PRIMARY, &pDispLayer));
DFBCHECK(pDispLayer->SetCooperativeLevel(pDispLayer,
DLSCL_ADMINISTRATIVE));

// Get the Display Interface Layer Configuration
DFBCHECK(pDispLayer->GetConfiguration(pDispLayer, &dispConfig));

// Set Display Layer Configuration Options
dispConfig.options |= DLOP_ALPHACHANNEL;

// Set the Display Interface Layer Configuration
DFBCHECK(pDispLayer->SetConfiguration(pDispLayer, &dispConfig));

// Set the Display Interface Layer Configuration
DFBCHECK(pDispLayer->GetDescription(pDispLayer, &dispDesc));

// Set Opacity on the Primary Surface
DFBCHECK(pDispLayer->SetOpacity(pDispLayer, 0x80));

/*If we are a gfx layer then create a surface the size of the image*/
surfaceDesc.width = maxWidth;
surfaceDesc.height= maxHeight;

surfaceDesc.caps  = DSCAPS_SYSTEMONLY | DSCAPS_PREMULTIPLIED;
surfaceDesc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT | DSDESC_WIDTH |
DSDESC_HEIGHT;
surfaceDesc.pixelformat = DSPF_ARGB;
DFBCHECK(pDfb->CreateSurface(pDfb, &surfaceDesc, &pImage));

/* Produce 4 different rectangles */
for (i = 0; i < 4; i++)
{
    int r, g, b, a;
    int x, y, w, h;

    r = random_no(0, 255);
    g = random_no(0, 255);
    b = random_no(0, 255);

    x = random_no(0, maxWidth - 1);
    w = random_no(1, maxWidth - x);

    y = random_no(0, maxHeight - 1);
    h = random_no(1, maxHeight - y);

    /* Set random colour and alpha (opaque) */
    /* Yes I know I cam make it transpart by making this Alpha value
0x80 */
    DFBCHECK( pImage->SetColor(pImage, r, g, b, 0xFF) );

    /* Draw randomly placed box */
    DFBCHECK( pImage->FillRectangle(pImage, x, y, w, h) );

    usleep(100000); /* Sleep for 0.1 sec */ 
}

DFBCHECK(pFrameBuffer->SetBlittingFlags(pImage, 
            DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_SRC_PREMULTCOLOR));

DFBCHECK(pFrameBuffer->Blit(pFrameBuffer, pImage, NULL, x, y));
    
/* Leave the image on the display for 'X' seconds */
sleep(delay);

Regards,
Max



_______________________________________________
directfb-users mailing list
directfb-users@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users

Reply via email to