How to do 2D image warp in OpenGL?

a “image warp” effect stretch the 4 points(left,right,top,bottom) of a 2D image to diffrent localtion,so the image is stretched to 4 different directions. I do my work using below code firstly:
glBegin(GL_QUADS);

glTexCoord2f(0,0);glVertex2f(x0,y0);
glTexCoord2f(0,1);glVertex2f(x1,y1);
glTexCoord2f(1,1);glVertex2f(x2,y2);
glTexCoord2f(1,0);glVertex2f(x3,y3);

glEnd();

But it fail,because the quad is divided into 2 triangles.I also test the Q texcoord from the NVSdk,but it require the top 2 vertexes and bottom 2 vertexes are horizontal(y0==y3,y1==y2),but I want my program can place the 4 vertexes anywhere,so how to do?

Some problem else:I found the R parameter is always 0 in NVIDIA sdk’s code(glTexCoord4f(s,t,0,q)),so what’s the use of it?Is it the key to solve my problem?

This is not an advanced topic.
Use GL_POLYGON rather than GL_QUADS.

And what is the difference between a 4 vertices GL_POLYGON and a GL_QUAD ?

I think this is a advanced question…

You don’t need to seta “r” component as that is only used in Cube/3D texture lookups.

You are going to calculate a “q” coordinate for each vertex to prevent the texture distortion. This will involve figuring out the texture rate of change at each vertex. I cannot help with this but I am sure there exists on google people with similar problems (with a generic solution)

Also make sure you read and understand:
http://www.r3.nu/~cass/qcoord/

He already claimed he read the q coordinate article.

The real solution is to tesselate your quad into 4096 quads, a mesh with 64 quads to a side, and interpolate your texture coordinates (and vertex coordinates) into this mesh. That will minimize distortion. If you want less distortion, use higher tesselation.