Game Development Reference
In-Depth Information
int baseIndex = 0;
// loop through and compute the triangles of each quad
for(inti=0;i<_numCellsPerCol; i++)
{
for(intj=0;j<_numCellsPerRow; j++)
{
indices[baseIndex] = i * _numVertsPerRow + j;
indices[baseIndex + 1] = i * _numVertsPerRow +
j+1;
indices[baseIndex + 2] = (i+1) * _numVertsPerRow + j;
indices[baseIndex + 3] = (i+1) * _numVertsPerRow + j;
indices[baseIndex + 4] = i * _numVertsPerRow +
j+1;
indices[baseIndex + 5] = (i+1) * _numVertsPerRow +
j+1;
// next quad
baseIndex += 6;
}
}
_ib->Unlock();
return true;
}
13.3 Texturing
The Terrain class provides two ways to texture the terrain. The obvi-
ous way is to simply load a previously made texture file and use that.
The following method implemented by the Terrain class loads a tex-
ture from the file into the _tex data member, which is a pointer to an
IDirect3DTexture9 interface. Internally, the Terrain::draw
method sets _tex before rendering the terrain.
bool loadTexture(std::string fileName);
At this point in the topic its implementation should be straightforward
to you. It is:
bool Terrain::loadTexture(std::string fileName)
{
HRESULT hr = 0;
hr = D3DXCreateTextureFromFile(
_device,
fileName.c_str(),
&_tex);
if(FAILED(hr))
return false;
Search WWH ::




Custom Search