   Bilinear Filtering Problem
   hi all,i am workign on a texture synthesis tool and tryed to implement bilinear filtering so that based on the fraction for the u,v coords the surrounding pixels are weighted. but it seams that there are some problems with my code.. artefacts.. problems when wrapping around. my texture is tileable and when teh u,v offsets are bigger than 255 i wrap with a &255. i have no clue whats wrogn atm so maybe one of u super elite guys knows how to solve that ? oh btw Texel is a struct that has the R/G/B components of one pixel in it! x,y is the offset for x and y into the texture with a fraction   Texel BilinearFilter(float x, float y, Texel * Texture){  //calculating only the fraction part  int offx = x;  int offy = y;  int offx2= offx+1;  int offy2= offy+1;    // calculating the distance used for the weighting   float distancex = fabs(x-(float)offx);   float distancey = fabs(y-(float)offy);  // weight for each pixel surrounding the position we want  float w4 = (distancex)*(distancey);  float w3 = (1.f-distancex)*(distancey);  float w2 = (distancex)*(1.f-distancey);  float w1 = (1.f-distancex)*(1.f-distancey);  // offx,offy-----------------offx2,offy  //| |  //| |  // offx,offy2----------------offx2,offy2  Texel Texel1,Texel2,Texel3,Texel4,Final;  // getting the 4 pixels surrounding the position we want   // and clamping if needed  Texel1 = Texture[(offx    &255) +((offy    &255)*256)];    //  Texel2 = Texture[((offx+1)&255) +((offy    &255)*256)];    //  Texel3 = Texture[(offx    &255) +(((offy+1)&255)*256)];   //  Texel4 = Texture[((offx+1)&255) +(((offy+1)&255)*256)];   //  // adding up the weighted pixels  Final.R =  Texel1.R*w1+Texel2.R*w2+Texel3.R*w3+Texel4.R*w4;  Final.G =  Texel1.G*w1+Texel2.G*w2+Texel3.G*w3+Texel4.G*w4;  Final.B =  Texel1.B*w1+Texel2.B*w2+Texel3.B*w3+Texel4.B*w4;  return Final;}
  hmm, main problem seems to be the clamping... dunno why but after clamping the code fucks up and doesnt filter correct so if there are pixels that dont need to be clamped in teh range of 0..255 the code works perfect hmm. ;From my position the glaringly obvious thing is in the first few lines. Compare yours with my modified version below. I would take the floor of the first two coordinates as my upper bounding pixels, and out and across as the other two. Where did the fabs() come from, it is not neccesary, the modified version has positive values by definition. You only needed it before because of the dogy way you where rounding.Try my changes i hope they work//calculating only the fraction part  int offx = floor(x);  int offy = floor(y);  int offx2= offx+1;  int offy2= offy+1;    // calculating the distance used for the weighting   float distancex = (float)offx-x;   float distancey = (float)offy-y; ;  well, i did the fabs because x,y can be also negative. lets say i have -5. this will be clamped with -5&255 what results in the same as 255-5=250. 