Platform SDK: DirectX

Creating Blending Stages

[C++]

A blending stage is a set of texture operations, together with their arguments, that define how textures are blended. When making a blending stage, C++ applications invoke the IDirect3DDevice7::SetTextureStageState method. The first call specifies the operation that will be performed. Two additional invocations define the arguments to which the operation will be applied. The following code fragment illustrates the creation of a blending stage.

// This example assumes that lpD3DDev is a valid pointer to an
// IDirect3DDevice7 interface.
 
// Set the operation for the 1st texture.
lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_ADD);
 
// Set arg1 for the texture operation.
lpD3DDev->SetTextureStageState(0, // First texture
       D3DTSS_COLORARG1,  // Set color arg 1
       D3DTA_TEXTURE);    // Color arg 1 value
 
// Set arg2 for the texture operation.
lpD3DDev->SetTextureStageState(0, // First texture
       D3DTSS_COLORARG2,  // Set color arg 2
       D3DTA_DIFFUSE);    // Color arg 2 value

Texel data in textures contain color and alpha values. Programs can define separate operations for both color and alpha values in a single blending stage. Each operation (color and alpha) has its own arguments. For details, see D3DTEXTURESTAGESTATETYPE.

Although not part of the Direct3D API, the following macros can also be inserted into your program to abbreviate the code required for creating texture blending stage.

#define SetTextureColorStage( dev, i, arg1, op, arg2 )       \
   dev->SetTextureStageState( i, D3DTSS_COLOROP, op);\
   dev->SetTextureStageState( i, D3DTSS_COLORARG1, arg1 );   \
   dev->SetTextureStageState( i, D3DTSS_COLORARG2, arg2 );   
 
#define SetTextureAlphaStage( dev, i, arg1, op, arg2 )       \
   dev->SetTextureStageState( i, D3DTSS_ALPHAOP, op);\
   dev->SetTextureStageState( i, D3DTSS_ALPHARG1, arg1 );    \
   dev->SetTextureStageState( i  D3DTSS_ALPHARG2, arg2 );    
[Visual Basic]

A blending stage is a set of texture operations, together with their arguments, that define how textures are blended. When making a blending stage, Visual Basic applications invoke the Direct3DDevice7.SetTextureStageState method. The first call specifies the operation that will be performed. Two additional invocations define the arguments to which the operation will be applied. The following code fragment illustrates the creation of a blending stage.

' This example assumes that d3dDev is a valid reference to a
' Direct3DDevice7 object.
 
' Set the color operation for the 1st texture.
Call d3dDev.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_ADD)
 
' Set arg1 to the texture color.
Call d3dDev.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE)
 
' Set arg2 to the iterated diffuse color.
Call d3dDev.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE)

Texel data in textures contain color and alpha values. Programs can define separate operations for both color and alpha values in a single blending stage. Each operation (color and alpha) has its own arguments. For details, see CONST_D3DTEXTURESTAGESTATETYPE.