问题
I have a GL_QUAD_STRIP that I am texture mapping. The quad strip folds back on itself to form a UV sphere. Essentially, the quad strip is not generally made of rectangles--instead, trapezoids.
I am getting texture distortion issues. The texture coordinates are correct (for example, they line up nicely where they should). The issue is on the trapezoidal faces themselves.
I would expect texels towards the larger end of a trapezoidal face to subtend larger area, yet the face seems broken into two triangles. It looks similar to affine texture mapping (but I don't think it is; it still seems perspective correct, and I wouldn't expect that to be used anyway).
I am aware that graphics cards usually reduce quads down into triangles internally, but I wouldn't expect that to affect texturing . . .
So, I don't know what's going on here. Any thoughts?
Here is an example of the undesired behavior. Low resolution globe texture, nearest filtering, no mipmaps or anisotropy:
回答1:
This is a classical problem when texturing a simple quad. It is due to the fact (like you guessed correctly) that the quad is broken down into individual triangles. These triangles are in turn textured independently.
The problem is, that the texture coordinates inside the triangle are interpolated linearly from the vertices (though perspective correct, but this doesn't help here). You can image it as the rasterizer not knowing the fourth vertex of this trapezoid, it only sees the individual triangles. Thus it assumes the transformation of the triangles into texture space to be completely affine, and thus for the triangle to be part of a parallelogram.
What you have to do to tackle this is to move away from the simple 2D affine texture space into a projective texture space, by using complete 4-dimensional texture coordinates instead of the simple 2D texcoords, like explained here. You basically do what the GL already does with perspective correct interpolation, but using your own perspective projection for the texture coordinates (in addition to the perspective projection already done for the vertex positions).
回答2:
Does each section render correctly when it is rendered head-on (so as to be completely square)?
You could potentially try the following command before rendering:
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
GL_PERSPECTIVE_CORRECTION_HINT Indicates the quality of color, texture coordinate, and fog coordinate interpolation. If perspective-corrected parameter interpolation is not efficiently supported by the GL implementation, hinting GL_DONT_CARE or GL_FASTEST can result in simple linear interpolation of colors and/or texture coordinates.
来源:https://stackoverflow.com/questions/10832909/quad-strip-texturing-distortion