Question

J'ai essayé de rendre un GL_QUAD (qui est façonné comme un trapézoïde) avec une texture carrée. J'aimerais essayer d'utiliser OpenGL uniquement pour réussir. En ce moment, la texture se déforment fortement et c'est vraiment ennuyeux.

Normalement, je chargerais la texture de calculer une homographie, mais cela signifie beaucoup de travail et une bibliothèque de programmation linéaire supplémentaire / une fonction de transformation linéaire directe. Je suis sous l'impression OpenGL peut simplifier ce processus pour moi.

J'ai regardé autour du Web et j'ai vu "Texturation correcte en perspective, Q coordonnées et GLSL" et "Mappage de texture asymétrique / cisaillé dans OpenGL".

Ceux-ci semblent supposer que vous ferez un certain type de calcul de l'homographie ou que vous utilisez certaines parties d'OpenGL, j'ignore ... des conseils?

Mise à jour:

J'ai lu "Navigation d'environnements statiques en utilisant la simplification et le morphing de l'espace d'image" [Pdf] - Page 9 Annexe A.

Il semble qu'ils désactivent la correction de la perspective en multipliant la coordonnée de texture (s, t, r, q) avec le sommet du composant Space Z de l'espace d'un modèle.

Donc, pour une coordonnée de texture donnée (S, R, T, Q) pour un quad en forme de trapézoïde, où les 4 composants sont:

(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) 

C'est aussi simple que GltexCoord4f (Svert.z, rvert.z, t, q * vert.z)? Ou est-ce que je manque un pas? comme jouer avec le glmmatrixmode glMatrixmode?

Mise à jour n ° 2:

Cela a fait l'affaire! Gardez cela à l'esprit les gens, ce problème est partout sur le Web et il n'y avait pas de réponses faciles. La plupart impliquaient directement recalculer la texture avec une homographie entre la forme d'origine et la forme transformée ... aka beaucoup d'algèbre linéaire et une dépendance externe Blas lib.

Était-ce utile?

La solution

Here is a good explanation of the issue & solution.

http://www.xyzw.us/~cass/qcoord/

Partly copied and adapted from above link, created by Cass

One of the more interesting aspects of texture mapping is the space that texture coordinates live in. Most of us like to think of texture space as a simple 2D affine plane. In most cases this is perfectly acceptable, and very intuitive, but there are times when it becomes problematic.

For example, suppose you have a quad that is trapezoidal in its spatial coordinates but square in its texture coordinates.

OpenGL will divide the quad into triangles and compute the slopes of the texture coordinates (ds/dx, ds/dy, dt/dx, dt/dy) and use those to interpolate the texture coordinate over the interior of the polygon. For the lower left triangle, dx = 1 and ds = 1, but for the upper right triangle, dx < 1 while ds = 1. This makes ds/dx for the upper right triangle greater than ds/dx for the lower one. This produces an unpleasant image when texture mapped.

Texture space is not simply a 2D affine plane even though we generally leave the r=0 and q=1defaults alone. It's really a full-up projective space (P3)! This is good, because instead of specifying the texture coordinates for the upper vertices as (s,t) coordinates of (0, 1) and (1, 1), we can specify them as (s,t,r,q) coordinates of (0, width, 0, width) and (width, width, 0, width)! These coordinates correspond to the same location in the texture image, but LOOK at what happened to ds/dx - it's now the same for both triangles!! They both have the same dq/dx and dq/dy as well.

Note that it is still in the z=0 plane. It can become quite confusing when using this technique with a perspective camera projection because of the "false depth perception" that this produces. Still, it may be better than using only (s,t). That is for you to decide.

Autres conseils

I would guess that most people wanting to fit a rectangular texture on a trapezoid are thinking of one of two results:

  1. perspective projection: the trapezoid looks like a rectangle seen from an oblique angle.
  2. "stretchy" transformation: the trapezoid looks like a rectangular piece of rubber that has been stretched/shrunk into shape.

Most solutions here on SO fall into the first group, whereas I recently found myself in the second.

The easiest way I found to achieve effect 2. was to split the trapezoid into a rectangle and right triangles. In my case the trapezoid was regular, so a quad and two triangles solved the problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top