I want to draw an image (using texture mapping) in a certain way that distorts the image. For example: take a square and squash the sides together at the top, giving a trapezium that has parallel top and bottom sizes, but the top side is shorter than the bottom. I want to map a square image onto this quad, in such a way that there is no distortion in the Y direction, but a scaling in the X direction that varies with y.

Mathematically it is something like:

-1 <= x <= 1, -1 <= y <= 1, 0 < a < 1,

and the mapping is (x,y) -> (x’,y’)

where

x’ = x*((a-1)*y + a+1)/2
y’ = y

(The top of the trapezium has -a < x’ < a).

I have found that splitting the image up into
triangles (or quads) requires a large number of faces to avoid ugly effects. What happens is straight lines in the image become kinked. Using tex mapping in the usual way, it seems to be impossible to avoid this kinking, all you can do is make the triangles so small that the kinking becomes unnoticeable.

You can use the homogenous q coordinate to get rid of the distortion. Replace
glTexCoord2f(s, t)
with
glTexCoord4f(sq, tq, 0, q)

Unfortunately I don’t remember how to calculate the q coordinate. I found the solution through trial and error and I don’t have the code here… It’s got something to do with the length of the edge, like for the bottom vertice q=the length of the bottom edge and for the top vertice it’s the length of the top edge. Or something else like that, could be 1/length too…

I have implemented a method using glTexCoord4d() (thanks Eero!), but although it produces a smooth mapping, as you say, it is not the mapping I want. Using qcoord gives a projective mapping (I think that’s the right term) - effectively the image looks as if it is painted on a horizontal plane and viewed from an elevated point. The mapping I want leaves y alone while squashing the image in the X direction. The difference is quite obvious when you see it.