Graphics Reference
In-Depth Information
class CModel {
.
// D3D texture reference
A: LPDIRECT3DTEXTURE9 m _ pTexture;
.
Source file. Model.cpp file
in the Model folder of the
D3D _ SimpleTexture project.
void CModel::LoadTextureFromFile( const wchar _ t * path) {
// Previous loaded another one?
if (m _ pTexture != NULL)
// free before allocating new ones
m _ pTexture->Release();
// Load file to graphics hardware
B:
if (FAILED(D3DXCreateTextureFromFile(pDevice,path,&m _ pTexture)))
// loading failed
m _ pTexture = NULL;
C:
}
Listing 12.10. Loading texture into graphics hardware.
corner, or
v
v
=
1
,
then
W u
W x ,
H v
H y )
uv
[
]=[
xy
]
T
(
c x ,−
c y )
S
(
T
(
c u ,
c v ) ,
in this case,
1
2 ,
1
2 )
uv
[
]=[
]
(
,
)
(
(
.
,
.
) .
xy
T
0
0
S
T
0
5
0
5
In this way,
u
=
x
×
0
.
5
+
0
.
5
,
v
=
=
(
×
.
+
.
) .
v
1
1
y
0
5
0
5
With uv texture placements defined on vertices, Listing 12.10 shows the D3D
support for loading file textures. At label A, the m _ pTexture is a reference to
a D3D-specific texture structure. Our job as a D3D programmer is to load an
appropriate texture into this structure and enable this structure for texture map-
ping while rendering primitives. At label B, we see that this D3D-specific struc-
ture is a limited resource, and we must properly manage (release) previously
Search WWH ::




Custom Search