![]() |
![]() |
![]() |
![]() |
Set the parameters for alpha blending in detail
void PgSetAlpha( unsigned long const alpha_op, PgMap_t const * const src_alpha_map, PgGradient_t const * const src_alpha_gradient, char unsigned const src_global_alpha, char unsigned const dst_global_alpha );
ph
PgSetAlpha() sets the parameters for an alpha-blending operation.
The alpha_op argument is the current operation. Currently, the function supports only these flags:
The other arguments are:
This map, of type PgMap_t, indicates the alpha blending to be applied to each individual pixel. The map is "pinned" to the origin of your draw command and is tiled if the dimensions of the map are smaller than the dimension of the drawing operation. The PgMap_t structure is defined as follows:
typedef struct _Pg_map { PhDim_t dim; char *map; } PgMap_t;
The members include:
Pixels are computed as follows when alpha blending is turned on:
Rd=(Rs * (src_multiplier)) + (Rd * (dst_multiplier)) Gd=(Gs * (src_multiplier)) + (Gd * (dst_multiplier)) Bd=(Bs * (src_multiplier)) + (Bd * (dst_multiplier))
where Rs, Gs, and Bs are the red, green, and blue settings for the source, and Rd, Gd, and Bd are those for the destination. So: so:
PgSetAlpha(Pg_ALPHA_OP_SRC_GLOBAL | Pg_BLEND_SRC_SRC_ALPHA | Pg_BLEND_DST_ONE_MINUS_SRC_ALPHA, NULL, NULL, 64, 0);
uses the following method to compute the resulting destination pixel:
RMask=0xFF GMask=0xFF BMask=0xFF
RShift=16 GShift=8 BShift=0
src_multiplier = 64 // (i.e. src_global_alpha) dst_multiplier = 192 // (i.e. 256 - src_global_alpha)
Rd=((Rs * src_multiplier) + (Rd * dst_multiplier)) >> 8 Gd=((Gs * src_multiplier) + (Gd * dst_multiplier)) >> 8 Bs=((Bs * src_multiplier) + (Bd * dst_multiplier)) >> 8
dest_pixel = ((Rd & RMask) << RShift) | ((Gd & GMask) << GShift) | ((Bd & BMask) << BShift)
This code:
unsigned char alphamapdata[8][8]= { {0x00, 0x40, 0x80, 0xC0, 0xFF, 0xC0, 0x80, 0x40 }, {0x40, 0x80, 0xC0, 0xFF, 0xC0, 0x80, 0x40, 0x00 }, {0x80, 0xC0, 0xFF, 0xC0, 0x80, 0x40, 0x00, 0x40 }, {0xC0, 0xFF, 0xC0, 0x80, 0x40, 0x00, 0x40, 0x80 }, {0xFF, 0xC0, 0x80, 0x40, 0x00, 0x40, 0x80, 0xC0 }, {0xC0, 0x80, 0x40, 0x00, 0x40, 0x80, 0xC0, 0xFF }, {0x80, 0x40, 0x00, 0x40, 0x80, 0xC0, 0xFF, 0xC0 }, {0x40, 0x00, 0x40, 0x80, 0xC0, 0xFF, 0xC0, 0x80 } }; PgMap_t alphamap; alphamap.dim.w=8; alphamap.dim.h=8; alphamap.map=alphamapdata; PgSetAlpha (Pg_ALPHA_OP_SRC_MAP | Pg_BLEND_SRC_SRC_ALPHA | Pg_BLEND_DST_ONE_MINUS_SRC_ALPHA, &alphamap, NULL, 0, 0);
is the same as above but uses the alpha map instead of an overall blend factor:
src_multiplier = *current_alpha_map_pos; dst_multiplier = 256 - *current_alpha_map_pos;
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PgAlphaOff(), PgAlphaOn(), PgSetAlphaBlend(), PhDim_t
"Alpha Blending Support" in the Raw Drawing and Animation chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |