[ Previous | Next | Contents | Glossary | Home | Search ]
GL3.2 for AIX: Graphics Library (GL) Technical Reference

blendfunction Subroutine

Purpose

Specifies the function to be used for alpha blending.

Libraries

Graphics Library

C (libgl.a)

FORTRAN (libfgl.a)

C Syntax

void blendfunction(Int32 sfactor, Int32 dfactor)

FORTRAN Syntax

SUBROUTINE BLENDF(sfactor, dfactor)
INTEGER*4 sfactor, dfactor

Description

In RGB mode, the system draws pixels using a function that blends the current (destination) RGBA values of the pixel with the RGBA values to be superimposed on that pixel (the source values).

Most often, blending is simple: the source RGBA values replace the destination RGBA values of the pixel. However, if a colored transparent primitive is drawn on top of another primitive, then the RGBA values of the new primitive must be blended with the RGBA values of the underlying primitive. (The transparency or opacity of a primitive can be stored as an alpha value.)

To determine the blended RGBA values of a pixel when drawing in RGB mode, the system uses the following functions:

Rblended = (Rsource * sfactor) + (Rdestination * dfactor) 
Gblended = (Gsource * sfactor) + (Gdestination * dfactor)
Bblended = (Bsource * sfactor) + (Bdestination * dfactor) 
Ablended = (Asource * sfactor) + (Adestination * dfactor)

where R is a red value, G is a green value, B is a blue value, and A is an alpha value. Blending is available with or without z-buffer mode. Blending works properly only in RGB mode. In color map mode, the results are unpredictable.

Blending is effectively deactivated by setting the sfactor parameter to BF_ONE and dfactor to BF_ZERO (the default values). RGB mode fill rates are significantly higher when blending is effectively deactivated.

By default, the destination RGBA values are read from the front buffer in single buffer mode and from the back buffer in double buffer mode. If the front buffer is not enabled in single buffer mode, the RGBA values are taken from the z-buffer. If the back buffer is not enabled in double buffer mode, the RGBA values are taken from the front buffer (if possible) or from the z-buffer. These default values can be changed with the readsource subroutine.

Blending factors use RGBA values converted to percentages of maximum value (255 in current hardware). To improve performance, conversion calculations are approximate. However, 0 converts exactly to 0.0, and maximum value converts exactly to 1.0.

Symbolic Constants
C FORTRAN Description
BF_ZERO BFZERO 0
BF_ONE BFONE 1
BF_DC BFDC (destination RGBA)/(maximum value)
BF_SC BFSC (source RGBA)/(maximum value)
BF_MDC BFMDC 1 - (destination RGBA)/(maximum value)
BF_MSC BFMSC 1 - (source RGBA)/(maximum value)
BF_SA BFSA (source alpha)/(maximum value)
BF_MSA BFMSA 1 - (source alpha)/(maximum value)
BF_DA BFDA (destination alpha)/(maximum value)
BF_MDA BFMDA 1 - (destination alpha)/(maximum value)

Parameters

sfactor Specifies a symbolic constant that identifies the blending factor by which to scale contributions from source (incoming) pixel RGBA (red, green, blue, alpha) values.
dfactor Specifies a symbolic constant that identifies the blending factor by which to scale contributions from destination (current) pixel RGBA values.

Implementation Specifics

This subroutine is part of GL in the AIXwindows Environment/6000 Version 1, Release 2 with AIXwindows/3D Feature.

The POWERgraphics GXT1000 supports source alpha blending. However, the GXT1000 does not support destination alpha blending. Destination blending is available using OpenGL.

When rendering semi-transparent polygons, it is recommended that z-buffering should be enabled, with the the z compare function set to ZF_LESS. Because the POWERgraphics GTO graphics adapter always renders "fat" triangles (that is, non-point sampled triangles whose upper and left edges are one pixel wider than those of a point-sampled triangle), the edges of bordering triangles are drawn twice, and thus double-blended, unless z-buffering is used to eliminate the double-rendering of edges. The POWERgraphics GTO graphics adapter forms all polygons into triangles; thus, the internal form of the polygon's edges become visible unless z-buffering is used to eliminate the edges.

The POWERgraphics GTO graphics adapter supports transparency by implementing a limited subset of the blendfunction subroutine functionality. The BF_SA and BF_MSA alpha-blending modes are supported when used in combination.

Semi-transparent lines and polygons are supported (this class includes circles, arcs, spline curves and NURBS surfaces); semi transparent blits (including raster text) are not supported. The alpha-blending factor must be a constant for the entire primitive; the interpolation of alpha values from vertex to vertex is not supported. Alpha values can be set with the cpack, c4[isf], or lmdef subroutines.

Files

/usr/include/gl/gl.h Contains C language constant and variable type definitions for GL.
/usr/include/gl/fgl.h Contains FORTRAN constant and variable type definitions for GL.

Related Information

Specifying RGBA color with a single, packed 32-bit integer using the cpack subroutine.

Specifying the source for pixels to be read with the readsource subroutine.

Writemasks and Logical Operations, and Working in Color Map and RGB Modes.


[ Previous | Next | Contents | Glossary | Home | Search ]