Jump to content
  • Advertisement
Sign in to follow this  
Knackebrod

OpenGL Distortion of texture on 2D Polygon

This topic is 3529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!