Table of Contents Glide Programming Guide



Download 6.22 Mb.
Page41/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   37   38   39   40   41   42   43   44   ...   106
GLIDEPGM
In this example, two images are blended so that the final color of each pixel is the sum of colors from the two images.

GrAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ONE, GR_BLEND_ZERO);


/* draw the first image */


grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ZERO);


/* draw the second image */


Example Using the Alpha Component.2 Blending two images, part II.


In this example, two images are blending so that the final color of each pixel is 75% of the first image and 25% of the second. When the second image is drawn, alpha is given a constant value of ¼ by setting the constant color and pointing the aother in the alpha combine unit to it.

GrAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ONE, GR_BLEND_ZERO);


/* draw the first image */

/* assumes RGBA format for colors */


grConstantColorValue(64);
grAlphaCombine(GR_COMBINE_FUNCTION_BLEND_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_CONSTANT, FXFALSE);
grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA, GR_BLEND_ONE, GR_BLEND_ZERO);
/* draw the second image */

  1. Table Using the Alpha Component.4 Alpha blending factors.

Four blending factors are specified in the grAlphaBlendFunction(). The rgbSrcFactor and alphaSrcFactor choices are given in the first table. The specified factors will be multiplied by the incoming RGBA values from the color and alpha combine units and added to the product of the destination factors and the alpha values stored in the alpha buffer. The possible destination factors are shown in the second table.
For alpha source and destination blend function factor parameters, Voodoo Graphics supports only GR_BLEND_ZERO and GR_BLEND_ONE.

If rgbSrcFactor or alphaSrcFactor is

the source blending factor fsrc or gsrc is

GR_BLEND_ZERO

0

GR_BLEND_ONE

1

GR_BLEND_DST_COLOR

cdst/255

GR_BLEND_ONE_MINUS_DST_COLOR

1– cdst/255

GR_BLEND_SRC_ALPHA

asrc/255

GR_BLEND_ONE_MINUS_SRC_ALPHA

1– asrc/255

GR_BLEND_DST_ALPHA

adst/255

GR_BLEND_ONE_MINUS_DST_ALPHA

1– adst /255

GR_BLEND_ALPHA_SATURATE

min( asrc/255, 1– adst/255 )




if rgbDestFactor or alphaDestFactor is

the destination blending factor fdst or gdst is

GR_BLEND_ZERO

0

GR_BLEND_ONE

1

GR_BLEND_SRC_COLOR

csrc/255

GR_BLEND_ONE_MINUS_SRC_COLOR

1– csrc/255

GR_BLEND_SRC_ALPHA

asrc/255

GR_BLEND_ONE_MINUS_SRC_ALPHA

1– asrc/255

GR_BLEND_DST_ALPHA

adst/255

GR_BLEND_ONE_MINUS_DST_ALPHA

1– adst/255

GR_BLEND_PREFOG_COLOR

csrc before fog is applied. See the Multi-Pass Fog section in Chapter Chapter 8. .

Example Using the Alpha Component.3 A compositing example.
A background scene is drawn with one alpha value, a polygonal cropping window is drawn with a second alpha value, and a foreground is mapped into the cropping window by discarding parts of the new scene that fall outside the cropping window. The example uses the alpha combine unit, alpha buffering, and alpha blending.
/* enable the alpha buffer */
grColorMask(FXTRUE, FXTRUE);

/* set alpha combine to generate zero alpha */


grAlphaCombine(GR_COMBINE_FUNCTION_ZERO, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_NONE, FXFALSE);

/* draw background scene */


/* clear out the cropping polygon */


grColorCombine(GR_COMBINE_FUNCTION_ZERO, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_NONE, FXFALSE);
grAlphaCombine(GR_COMBINE_FUNCTION_ZERO, GR_COMBINE_FACTOR_NONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_NONE, FXFALSE);

/* draw cropping window */


/* set alpha blend unit to use destination alpha to select */


/* new pixel or old one */
grAlphaBlendFunction(GR_BLEND_DST_ALPHA, GR_BLEND_ONE_MINUS_DST_ALPHA, GR_BLEND_ZERO, GR_BLEND_ONE);

/* set color combine and alpha combine back to defaults */


grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_ITERATED, FXFALSE);
grAlphaCombine(GR_COMBINE_FUNCTION_ SCALE_OTHER, GR_COMBINE_FACTOR_ONE, GR_COMBINE_LOCAL_NONE, GR_COMBINE_OTHER_CONSTANT, FXFALSE);

/*draw the foreground scene */



Download 6.22 Mb.

Share with your friends:
1   ...   37   38   39   40   41   42   43   44   ...   106




The database is protected by copyright ©ininet.org 2024
send message

    Main page