Jump to content
  • Advertisement
Sign in to follow this  
Fuza

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.

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

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.

screenshot20110221at322.png

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.

dfgdfgdgdfg.png

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 this post


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


Link to post
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!

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!