PDA

View Full Version : How to do 2D image warp in OpenGL?

pango
12-10-2004, 04:04 AM
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:

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?

Aeluned
12-10-2004, 12:36 PM
This is not an advanced topic.

ZbuffeR
12-10-2004, 03:33 PM
And what is the difference between a 4 vertices GL_POLYGON and a GL_QUAD ?

sqrt[-1]
12-10-2004, 06:19 PM
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/

jwatte
12-11-2004, 07:32 AM