another error:

for nPixel := 0 to xWidth-1 do
begin
// extract pixel data

r := pSrc[nPixel];
g := pSrc[nPixel+1];
b := pSrc[nPixel+2];
Note how in the FOR loop Npixel is incremented by 1, when npixel = 0 it works like you think, but note when npixel = 1 then "r" will have the value you placed in "g" in prior interations, and so on. Instead using "npixel" for your array index you need to use a index that is incremented by 3.


Your fill texture rutine works placing pixel by pixel; i guess you do that becouse the source texture is not in the same format as the target; but if for any chance both source and target are the same format and size then i suggest you just copy the whole block memory from source to target, one simple move() pascal procedure will do the job.