Note that there are some explanatory texts on larger screens.

plurals
  1. POtexture mapping a trapezoid with a square texture in OpenGL
    text
    copied!<p>I've been trying to render a GL_QUAD (which is shaped as a trapezoid) with a square texture. I'd like to try and use OpenGL only to pull this off. Right now the texture is getting heavily distorted and it's really annoying.</p> <p>Normally, I would load the texture compute a homography but that means a lot of work and an additional linear programming library/direct linear transform function. I'm under the impression OpenGL can simplify this process for me.</p> <p>I've looked around the web and have seen <a href="http://hacksoflife.blogspot.com/2009/11/perspective-correct-texturing-q.html" rel="nofollow">"Perspective-Correct Texturing, Q Coordinates, and GLSL"</a> and <a href="http://www.gamedev.net/topic/419296-skewedsheared-texture-mapping-in-opengl" rel="nofollow">"Skewed/Sheared Texture Mapping in OpenGL"</a>.</p> <p>These all seem to assume you'll do some type of homography computation or use some parts of OpenGL I'm ignorant of ... any advice?</p> <p><strong>Update:</strong></p> <p>I've been reading <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1.9091" rel="nofollow">"Navigating Static Environments Using Image-Space Simplification and Morphing"</a> [<a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.1.9091&amp;rep=rep1&amp;type=pdf" rel="nofollow">PDF</a>] - page 9 appendix A.</p> <p>It looks like they disable perspective correction by multiplying the (s,t,r,q) texture coordinate with the vertex of a model's world space z component.</p> <p>so for a given texture coordinate (s, r, t, q) for a quad that's shaped as a trapezoid, where the 4 components are:</p> <pre><code>(0.0f, 0.0f, 0.0f, 1.0f), (0.0f, 1.0f, 0.0f, 1.0f), (1.0f, 1.0f, 0.0f, 1.0f), (1.0f, 0.0f, 0.0f, 1.0f) </code></pre> <p>This is as easy as glTexCoord4f (s<em>vert.z, r</em>vert.z, t, q*vert.z)? Or am I missing some step? like messing with the GL_TEXTURE glMatrixMode?</p> <p><strong>Update #2:</strong></p> <p>That did the trick! Keep it in mind folks, this problem is all over the web and there weren't any easy answers. Most involved directly recalculating the texture with a homography between the original shape and the transformed shape...aka lots of linear algebra and an external BLAS lib dependency.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload