Graphics Reference
In-Depth Information
bool
UWBD3D
_
DrawHelper::EnableBlending(
bool
on ) {
.
Source file.
uwbgl
_
D3DDrawHelper5.cpp
file in the
D3D Files/
D3D_DrawHelper
// Alpha blending is enabled for this primitive
subfolder
A:
if
(on){
// 1. Enable D3D alpha blending
pDevice->SetRenderState(D3DRS
_
ALPHABLENDENABLE,TRUE);
// 2. Define
A
s
=
UWBGL
_
D3D
_
Lib13
of
the
project.
S
α
pDevice->SetRenderState(D3DRS
_
SRCBLEND,D3DBLEND
_
SRCALPHA);
// 3. Define
A
d
=
1
−
S
α
pDevice->SetRenderState(D3DRS
_
DESTBLEND,D3DBLEND
_
INVSRCALPHA);
// 4. Blending function=Addition
pDevice->SetRenderState(D3DRS
_
BLENDOP,D3DBLENDOP
_
ADD);
// Alpha blending is disabled for this primitive
B:
}
else
// Disable D3D Alpha blending
pDevice->SetRenderState(D3DRS
_
ALPHABLENDENABLE, FALSE);
.
Listing 12.7.
Enabling blending for the D3D API.
Tutorial 12.3.
Project Name:
D3D
_
AlphaBlending
Library Support:
UWB_MFC_Lib1
UWB_D3D_Lib13
Tutorial 12.3. Alpha Blending
•
Goal.
Demonstrate alpha blending by allowing the user to change the
blending factors interactively.
•
Approach.
Implement a simple scene with a circle and a square that allows
the user to set the
α
channel for both of the primitives.
Figure 12.9 is a screenshot of running Tutorial 12.3. This tutorial has enabled the
“Blending” checkbox in the
PrimitiveControl
. This checkbox directly controls
the
EnableBlending()
attribute of the primitive highlighted in the
SceneTree
Control
. Now, select the “Circle” object from the
SceneTreeControl
and en-
able the “Blending” checkbox. Notice that the circle becomes semi-transparent
where we can see through it and observe the blue square behind it. Now, if we ad-
just the
Figure 12.9.
Tutorial
12.3.
channel via the “A” slider bar, we can adjust the degree of transparency
of the circle. In this tutorial, we see that the transparency/opacity functionality can
be accomplished with the blending functionality programmed in Listing 12.7.
α
Search WWH ::
Custom Search