In one of my games, I have a minimap. the question that has been buzzing around in my mind for a while is "Why wont this function work correctly?" I did some experimenting and I narrowed my selection down to a memset function. Here are the lines of code.
...
D3DLOCKED_RECT sRect;
sightTexture->LockRect(0, &sRect, NULL, NULL);
BYTE *bytes = (BYTE*)sRect.pBits;
memset(bytes, 0, sRect.Pitch*sRect.Pitch);
float intensity = 1.3f;
D3DXVECTOR2 center = D3DXVECTOR2(32.0f, 32.0f);
for(int y=0;y<64;y++)
for(int x=0;x<64;x++)
{
float d = D3DXVec2Length(&(center - D3DXVECTOR2((float)x, (float)y)));
int value = (int)(((32.0f - d) / 32.0f) * 255.0f * intensity);
if(value < 0)value = 0;
if(value > 255)value = 255;
bytes[x + y * sRect.Pitch] = value;
}
sightTexture->UnlockRect(0);
...
Where is the code going wrong?
I found this technique on an old programming website I used to use...
Without the memset function, only 1/3 of my minimap gets rendered...