# OpenGL Skewed Triangles?

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

## Recommended Posts

Hello. Was hoping one of you OpenGL gurus had an idea of what to do here..

My end goal is to draw a road that kinda fades to a vanishing point.. I can get the right vertices, but I cannot figure out how to get my texture to behave correctly. This is for an iOS app, so I am unable to try with GL_QUADS.

Here's a screen where I am doing Tris instead of tri strips, helps to illustrate what's going on:

The yellow lines are what I would like it to look like.

The problem is basically taking a skewed quad and having it stretch out a texture to have the edges line up properly.

Any help is greatly appreciated!

- Nick

##### Share on other sites
Your problem seems to be the same as is described on the following page: http://home.xyzw.us/~cass/qcoord/

You can correct it rather easily with shaders. What you need to do is provide a third coordinate which is the scale-factor of the texture, relative some fixed value (for example the other side, or simply 1.0). So if you let the bottom side of your road be 1.0, then where the road is 50% as wide as the bottom side the scale-factor is 0.5, and where it's 75% the scale-factor is 0.75 etc.
Then you multiply your X texture-coordinate with the scale-factor, and interpolate the vec3 (x*z, y, z) where z = scale-factor, instead of your normal x, y 2D texcoord. In the pixel shader, calculate your corrected x,y coords by setting x = x / z.

##### Share on other sites

Your problem seems to be the same as is described on the following page: http://home.xyzw.us/~cass/qcoord/

You can correct it rather easily with shaders. What you need to do is provide a third coordinate which is the scale-factor of the texture, relative some fixed value (for example the other side, or simply 1.0). So if you let the bottom side of your road be 1.0, then where the road is 50% as wide as the bottom side the scale-factor is 0.5, and where it's 75% the scale-factor is 0.75 etc.
Then you multiply your X texture-coordinate with the scale-factor, and interpolate the vec3 (x*z, y, z) where z = scale-factor, instead of your normal x, y 2D texcoord. In the pixel shader, calculate your corrected x,y coords by setting x = x / z.

Awesome man, that seems to be the ticket! I don't actually have it working right yet, but I will be able to get it from there. Gracias!

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 33
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631745
• Total Posts
3002004
×