klurie
klurie

Reputation: 1060

texture mapping onto triangle mesh

I would like to map an image onto a triangle mesh. For each triangle, I know the positions of the vertices in UV space as well as in the image/texture space.

OpenGL solves this problem by defining the correspondences between vertices in UV space and image/texture space.

  1. Is OpenGL just defining a linear transformation between the correspondences to determine how to interpolate the texture?
  2. Why isn't necessary to define a homography to do the mapping? In what cases would defining a homography be necessary? (This would necessitate having four point correspondences instead of three.)

Upvotes: 0

Views: 2233

Answers (1)

ebbs
ebbs

Reputation: 435

To answer your first question:

OpenGL will assign your texture with UV-coordinates where (0,0) is the lower left corner and (1,1) is the upper right. Then the UV-coordinates (texture coordinates) of each vertex will be (linearly) interpolated over its corresponding triangles during the rasterization. Each fragment of the triangle will then get an interpolated texture coordinate which can be used to fetch the corresponding value from the texture. How the interpolation over the texture is done depends on the parameters sent when creating the texture:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

For magnification and minification respectively. The GL_LINEAR parameter will result in a linear interpolation between the texels and, for example, GL_NEAREST gives you nearest neighbor. If you use mip-mapping you may pass some other parameters as well. More about that in the documentation:

https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml

About your second question I am not too sure, but I believe that my answer should partly cover it atleast.

Upvotes: 2

Related Questions