The method of subdividing the cube faces is a cheating method but trust me it works really well and the warping will not be noticeable on the cube, but for satisfaction, it's better to have perspective correct texturing.
Here is in essence what I was saying, here's the slow way of doing it in pseudo code.
UU = U/Z
VV = V/Z
ZZ = 1/Z
for x=start to end
u2 = UU / ZZ
v2 = VV / ZZ
plot (x, y, (texel u2,v2)
UU += deltaUU
VV += deltaVV
ZZ += deltaZZ
end
Obviously the problem with the above is the two divides but we can get rid of one of the divides like this ;
for x=start to end
reciprocal = 1/ZZ
u2 = UU * reciprocal
v2 = VV * reciprocal
plot (x, y, (texel u2,v2)
UU += deltaUU
VV += deltaVV
ZZ += deltaZZ
end
There is another method of doing perspective correct (which I believe is faster, if you google "3 magic vectors" you will find more info on that method, but the one I described is easier to grasp.