Graphics Reference
In-Depth Information
void
CModel::DrawModel() {
Source file.
Model.cpp
file
in the
Model
folder of the
D3D
_
SimpleTexture
project.
// user has selected texture mapping
if
(m
_
EnableTexture && (m
_
pTexture != NULL))
// Enable graphics API texture mapping
pDevice->SetTextureStageState(... D3DTOP
_
SELECTARG1);
// Select a current texture map
pDevice->SetTexture(0, m
_
pTexture);
// slider bars transformation setting
A:
m
_
xform.SetUpModelStack(draw
_
helper);
// either draw the circle
B:
if
(dt
_
circle==m
_
DrawType) DrawUnitCircle( pDevice );
// or draw the square
else
DrawUnitSquare( pDevice );
// Switch off texture when done
C:
if
(m
_
EnableTexture && (m
_
pTexture != NULL))
// Disable graphics API texture mapping
pDevice->SetTextureStageState(... D3DTOP
_
DISABLE);
// Set curren texture map to NULL
pDevice->SetTexture(0, NULL);
D:
}
Listing 12.11.
Drawing with file texture.
allocated versions. At label C, we see the utility function that, given a valid
path
to an image file, properly loads the
m
_
pTexture
structure into the D3D
pDevice
.
Listing 12.11 shows that to draw with the loaded texture, we must enable the
texture-mapping functionality and define how to use the texel values (at label
A). At label B, we set up the
WORLD
matrix processor to support user-specified
transformations. At label C, either the circle or square will be drawn. At label
D, to ensure the proper rendering state, texture-mapping functionality is switched
off after the primitive is drawn.
This tutorial shows us that we can switch texture mapping on/off at any point
before/after drawing primitives. This means that in our primitive hierarchy, we
can define texture mapping as a per-primitive attribute and control the texturing
of each primitive independently.
UWBGL_D3D_Lib13 Support for File Texture
Change summary.
See p. 525
for a summary of changes to
the library.
As pointed out in Section 12.3.5 and demonstrated in Tutorial 12.4, the important
three steps in programming with file texture mapping are as follows.
Search WWH ::
Custom Search