   painting a texture
  I trying to paint a texture, it works but I want to do it with locking a specific rectangle of a texture, because I paint a very little part of it. here is my code  D3DLOCKED_RECT temp;   RECT rect;  rect.left = xmin;  rect.right = xmax;  rect.top = ymin;  rect.bottom = ymax;    if(paints[subset]->LockRect(0, &temp, &rect, 0) != D3D_OK) ALERT;  unsigned int *a = (unsigned int*)temp.pBits;  for(int i=xmin; i<xmax; i++){    for(int j=ymin; j<ymax; j++){ if(pixelInSphere(i, j, pos, tri, uvMax, uvMin, AreaABC, paintSize)){a[i+j*paintSize] = color; }    }  }  if(paints[subset]->UnlockRect(0) != D3D_OK) ALERT;rectangle I am painting is between xmin, xmax, ymin and ymax. but it does not work. it works if I lock the whole texture.I tried switching x and y but didn't work either :(   
  The code is mostly correct, but remember even though you are locking a rect, memory is linear so you don't get a rectangular section of memory. What you get is the start of the memory and the pitch,i.e how many bytes there is in a line of memory. Together with the starting location and dimension you can 'simulate' rectangular memory. That is why D3DLOCKED_RECT has a pointer to the memory and the pitch. To get your code to work you need to write at most xmax - xmin pixel to the memory, skip to the next line by adding pitch to the beginning of the present row and so on until you have done ymax - ymin rows. Be careful though when incrementing the memory pointer to the next row, since you are using an unsigned int pointer and pitch is in bytes.   ;  thanks, I changed it with  for(int i=0; i<xmax-xmin; i++){    for(int j=0; j<ymax-ymin; j++){ if(pixelInSphere(i+xmin, j+ymin, pos, tri, uvMax, uvMin, AreaABC, paintSize)){a[i+j*paintSize] = color; }    }  }and it works. 0, 0 is beginning of our rectangle but pitch is still same.now I should get rid of that pixelInSphere method :D it is too expensive. it first converts pixel into 3d and tests if it is in inside of a sphere :) and it does it for each pixel   