Original Post
Im making a texture blending routien but im getting an error
ill hilight the line that causes the error
CFrameWorkApplication::CPUTextureBlender()
{
//Obtain the final textures surface
int i,j,count,scale;
int col;
D3DLOCKED_RECT TextureLR;
unsigned int *TextureBits;
unsigned int TexturePitch;
D3DSURFACE_DESC TextureDesc;
D3DLOCKED_RECT SourceTextureLR[4];
unsigned int *SourceTextureBits[4];
unsigned int SourceTexturePitch[4];
D3DSURFACE_DESC SourceTextureDesc[4];
terrRenderTarget->GetLevelDesc(0, &TextureDesc);
terrRenderTarget->LockRect( 0, &TextureLR, 0, 0 );
TextureBits=(unsigned int*)TextureLR.pBits;
TexturePitch=TextureLR.Pitch/4;
//get the source textures surface
for(i=0;i<4;i++)
{
terrTexture[i]->GetLevelDesc(0, &SourceTextureDesc[i]);
terrTexture[i]->LockRect( 0, &SourceTextureLR[i], 0, 0 );
SourceTextureBits[i]=(unsigned int*)SourceTextureLR[i].pBits;
SourceTexturePitch[i]=TextureLR.Pitch/4;
}
scale = rendertargetsize/(terrSizeX*blendmapscale);
//Split this part up for testing purposes
//Cycle throught the blend maps and apply the parts that are 255
for(count=0;count<4;count++)
{
for(i=0;i<(int)TextureDesc.Width;i++)
for(j=0;j<(int)TextureDesc.Height;j++)
{
if(i<rendertargetsize&&j<rendertargetsize)
{
//read the valuse out of the height map
//if its 255 then plot it on the rendertarget
if(BlendMap[count][(j/scale)*(terrSizeX*blendmapscale)+(i/scale)]==255)
{
//get the colour from the source texture and put it on the
//render target
//col=D3DCOLOR_ARGB(255,0,255,0);//((DWORD*)SourceTextureLR.pBits)[count][SourceTextureDesc[count].Width*j+i];
***********************************************************
TextureBits[TextureDesc.Width*j+i] =0;//D3DCOLOR_ARGB(255,0,255,0);
***********************************************************
}
}
}
}
terrRenderTarget->UnlockRect(0);
terrTexture[0]->UnlockRect(0);
terrTexture[1]->UnlockRect(0);
terrTexture[2]->UnlockRect(0);
terrTexture[3]->UnlockRect(0);
}