Figure 7   Creating a Texture Stage


 // use the utility functions in D3Dutils to simplify loading & accessing a
 // texture
  D3DTextr_CreateTexture( "my.bmp" );
 // now assign the texture to stage 0 for this D3D device
 // (Note use of another utility function to get texture pointer)
 pd3dDevice->SetTexture(0, D3DTextr_GetTexture( "my.bmp" )  );
 
 // now we can set the color blending modes
 // this comes in three steps. You need to define the two
 // arguments and the operator
 // specify the two arguments. The first color argument
 // sets the texture color the second argument sets
 // the diffuse color.
 pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
 pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
 // select the color operator and set it to "modulate" (multiply)
 pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );


Figure 8   Blending Operations

D3DBLEND_ZERO
Blend factor is (0, 0, 0, 0). This element has no influence on the end color.
D3DBLEND_ONE
Blend factor is (1, 1, 1, 1). The pixel's RGBa value is passed straight through.
D3DBLEND_SRCCOLOR
Blend factor is (Rs, Gs, Bs, As). The source RGBa values are used.
D3DBLEND_INVSRCCOLOR
Blend factor is (1-Rs, 1-Gs, 1-Bs, 1-As). The inverse source values are used.
D3DBLEND_SRCALPHa
Blend factor is (As, As, As, As). The source alpha values are used.
D3DBLEND_INVSRCALPHa
Blend factor is (1-As, 1-As, 1-As, 1-As). The inverse source alpha values are used.
D3DBLEND_DESTALPHa
Blend factor is (Ad, Ad, Ad, Ad). The destination alpha values are used.
D3DBLEND_INVDESTALPHa
Blend factor is (1-Ad, 1-Ad, 1-Ad, 1-Ad). The inverse destination alpha values are used.
D3DBLEND_DESTCOLOR
Blend factor is (Rd, Gd, Bd, Ad). The destination RGBa values are used.
D3DBLEND_INVDESTCOLOR
Blend factor is (1-Rd, 1-Gd, 1-Bd, 1-Ad). The inverse destination RGBa values are used.
D3DBLEND_SRCALPHASAT
Blend factor is (f, f, f, 1); f = min(As, 1-Ad). Source alpha saturate.
D3DBLEND_BOTHSRCALPHa
Obsolete. For DirectX 6.0 and later, you can achieve the same effect by setting the source and destination blend factors to D3DBLEND_SRCALPHa and D3DBLEND_INVSRCALPHa in separate calls.
D3DBLEND_BOTHINVSRCALPHa
Source blend factor is (1-As, 1-As, 1-As, 1-As), and destination blend factor is (As, As, As, As). This blend mode is supported only for sources. The destination blend selection is overridden.


Figure 9   Settings for Blending Operations

Control Members
D3DTOP_DISABLEDTOP_DISABLE
Disables the output from this texture stage and all stages with a higher index. To disable all texture mapping, set this operation for the first texture stage (stage 0).
D3DTOP_SELECTARG1
Use this texture stage's first color or alpha argument, unmodified, as the output. This operation affects the color argument when used with the D3DTSS_COLOROP texture stage state, and the alpha argument when used with D3DTSS_ALPHAOP.
D3DTOP_SELECTARG2
Use this texture stage's second color or alpha argument, unmodified, as the output. This operation affects the color argument when used with the D3DTSS_COLOROP texture stage state, and the alpha argument when used with D3DTSS_ALPHAOP.
Modulation Members
D3DTOP_MODULATE
Multiply the components of the arguments together. Note that multiplying two numbers that are less than 1 means that the result is always going to be darker. (See the next two members.)
D3DTOP_MODULATE2X
Multiply the components of the arguments and shift the products to the left one bit (effectively multiplying them by 2) for brightening. Still clamped [0,1].
D3DTOP_MODULATE4X
Multiply the components of the arguments and shift the products to the left two bits (effectively multiplying them by 4) for brightening. Still clamped [0,1].
Addition and Subtraction Members
D3DTOP_ADD
Add the components of the arguments.
D3DTOP_ADDSIGNED
Add the components of the arguments with a -0.5 bias, making the effective range of values from -0.5 to 0.5.
D3DTOP_ADDSIGNED2X
Add the components of the arguments with a -0.5 bias, and shift the products to the left one bit.
D3DTOP_SUBTRACT
Subtract the components of the second argument from those of the first argument.
D3DTOP_ADDSMOOTH
Add the first and second arguments, then subtract their product from the sum.
Linear Alpha Blending Members
D3DTOP_BLENDDIFFUSEALPHa
Linearly blend this texture stage using the interpolated alpha from each
D3DTOP_BLENDTEXTUREALPHa
vertex (D3DTOP_BLENDDIFFUSEALPHA), alpha from this stage's
D3DTOP_BLENDFACTORALPHa
texture (D3DTOP_BLENDTEXTUREALPHA), a scalar alpha
D3DTOP_BLENDCURRENTALPHa
(D3DTOP_BLENDFACTORALPHA) set with the D3DRENDERSTATE_TEXTUREFACTOR render state, or the alpha taken from the previous texture stage (D3DTOP_BLENDCURRENTALPHA).
D3DTOP_BLENDTEXTUREALPHAPM
Linearly blend a texture stage that uses a premultiplied alpha. The RGBa format used by this image already has its RGB values multiplied by the alpha value.
Specular Mapping Members
D3DTOP_PREMODULATE
Modulate this texture stage with the next texture stage.
D3DTOP_MODULATEALPHA_ADDCOLOR
Modulate the second argument's color using the first argument's alpha, then add the result to argument one. This operation is supported only for color operations (D3DTSS_COLOROP).
D3DTOP_MODULATECOLOR_ADDALPHa
Modulate the arguments, then add the first argument's alpha. This operation is supported only for color operations (D3DTSS_COLOROP).
D3DTOP_MODULATEINVALPHA_ADDCOLOR
Similar to D3DTOP_MODULATEALPHA_ADDCOLOR, but use the inverse of the first argument's alpha. This operation is supported only for color operations (D3DTSS_COLOROP).
D3DTOP_MODULATEINVCOLOR_ADDALPHa
Similar to D3DTOP_MODULATECOLOR_ADDALPHA, but use the inverse of the first argument's color. This operation is supported only for color operations (D3DTSS_COLOROP).
Bump Mapping Members
D3DTOP_BUMPENVMAP
Perform per-pixel bump mapping using the environment map in the next texture stage (without luminance). This operation is supported only for color operations (D3DTSS_COLOROP).
D3DTOP_BUMPENVMAPLUMINANCE
Perform per-pixel bump mapping using the environment map in the next texture stage (with luminance). This operation is supported only for color operations (D3DTSS_COLOROP).
D3DTOP_DOTPRODUCT3
Modulate the components of each argument (as signed components), add their products, then replicate the sum to all color channels, including alpha. This operation is supported for color and alpha operations.