Distortion of texture on 2D Polygon

Started by
3 comments, last by Erik Rufelt 15 years, 3 months ago
Hi, I am working entirely in 2D with an orthogonal projection. I am trying to render a texture-mapped, triangulated polygon. The texture mapping coordinates (S,T) don't always match the spatial coordinates (X,Y) of the polygon, and through this I am hoping to achieve a "warping" effect on the texture. This means that for each vertex, if the X,Y coordinates of the vertex differ from its S,T coordinates, the texture should be distorted accordingly. Here is a picture of what I would like to do: And here is what is actually being rendered for now: I have seen a solution for this problem, which involves using the Q texture coordinate and adjusting the S and T coordinates. I have toyed with this for a while, but it only seems to work for quads. Does anyone know of a way to do this? Thanks in advance. /Knäckebröd PS: Links to the Q coordinate adjustment solution: one two
Advertisement
Are you actually drawing that as a GL_POLYGON? Because texture coord interpolation is ill-defined for polys like you're trying to draw. You should manually break your poly into multiple triangles (which do have well defined texture coord interpolation) and calculate the texture coords yourself.

Depending on what you're trying to do you *may* be able to do this easiest by converting to a texture fan (by adding a center vertex at the average position of the poly coords (and having the uvs also the average) and making triangles out to all of the poly edges). That'll break if you have much more complicated polys though. What exactly are you using this for?
I'm not using GL_POLYGON; the polygon is tessellated by a GLUtesselator.

A triangle fan is a good idea for simple polygons, unfortunately I have to be able to render polygons with weird shapes, and a triangle fan couldn't do the job.

I am writing a program that lets you draw arbitrary polygons and animate them. I wish to add a "texture mapping" function that would allow you to map a texture to a polygon, and distort the texture properly. (i.e. after you have mapped the texture to the polygon, if you move a vertex of the polygon, the texture should stretch or squeeze, depending on where you move it).
Has no one really run into this problem before?
What triangles are rendered?
That is.. in your rendered shape, we don't see where the actual geometry edges are. Try rendering a wireframe.
Also, note down the actual coordinates and texture coordinates used to render each vertex, and try them in a simple render without using your tesselator. You must somehow use more than the regular S/T coordinates, like the Q coordinate you mentioned, or the warping will depend on which triangles you choose.
The strangeness in your picture is.. strange.. I don't understand how you can get that result. It doesn't seem to have the correct texture coordinates.. I can't see any triangle configuration that would give that result with 5 vertices.

This topic is closed to new replies.

Advertisement