Game Development Reference
In-Depth Information
&_tex);
if(FAILED(hr))
return false;
D3DSURFACE_DESC textureDesc;
_tex->GetLevelDesc(0 /*level*/, &textureDesc);
// make sure we got the requested format because our code
// that fills the texture is hard coded to a 32-bit pixel depth.
if( textureDesc.Format != D3DFMT_X8R8G8B8 )
return false;
D3DLOCKED_RECT lockedRect;
_tex->LockRect(0/*lock top surface*/, &lockedRect,
0 /* lock entire tex*/, 0/*flags*/);
// fill the texture
DWORD* imageData = (DWORD*)lockedRect.pBits;
for(inti=0;i<texHeight; i++)
{
for(intj=0;j<texWidth; j++)
{
D3DXCOLOR c;
// get height of upper-left vertex of quad.
float height = (float)getHeightmapEntry(i, j)/_heightScale;
// set the color of the texel based on the height
// of the quad it corresponds to.
if( (height) < 42.5f ) c = d3d::BEACH_SAND;
else if( (height) < 85.0f ) c = d3d::LIGHT_YELLOW_GREEN;
else if( (height) < 127.5f)c=d3d::PUREGREEN;
else if( (height) < 170.0f)c=d3d::DARK_YELLOW_GREEN;
else if( (height) < 212.5f)c=d3d::DARKBROWN;
else
c = d3d::WHITE;
// fill locked data, note we divide the pitch by four
// because the pitch is given in bytes and there are
// 4 bytes per DWORD.
imageData[i * lockedRect.Pitch/4+j]=(D3DCOLOR)c;
}
}
_tex->UnlockRect(0);
// light the terrain
if(!lightTerrain(directionToLight))
{
::MessageBox(0, "lightTerrain() - FAILED", 0, 0);
return false;
}
// fill mipmaps
hr = D3DXFilterTexture(
_tex,// texture to fill mipmap levels
0,
// default palette
Search WWH ::




Custom Search