Uv-Coordinates: Theoretical questions

霸气de小男生 提交于 2020-01-06 17:59:48

问题


In my previouse question I had some problems regarding texturing in OpenGL ES 2.0. With some help this problem is solved now, but some related questions have appeared:

  1. How do I know wheather uv-coordinate and vertex-coordinates fit together? I thought there is a bijection between the vertex and uv, for example (0,0) of vertex to (0,0) of uv, and (width,0) of vertex to (1,0), and (0,height) of vertex to (0,1) of uv. But since the texture appears flipped in my example, the thought might be wrong?
  2. How can I know the second param of the glVertexAttribPointer method? Why do I have to set 2 in this case?

回答1:


Bullet point 1 sounds like it is related to the texture origin in GL.

(0,0) maps to the lower-left corner of a texture image.

If you have assumed something similar to another graphics API (maybe one where (0,0) is top-left), that will not help your understanding.

Bullet point 2, assuming it is for texture coordinates, defines the 2D coords.

If you are talking about calling glVertexAttribPointer (...) with your texture coordinates, that is because they are 2-dimensional. Texture coordinates can be 1,2,3 or 4-dimensional as unusual as that may sound at first. The most common use-case is 2D, but 3D and 4D texture coordinates have specialized applications of their own.

In fact, if you call glVertexAttribPointer (..., 2, ...), the vertex attribute gets expanded automatically like this by GLSL:

vec2 (x,y) ==> vec4 (x,y,0.0,1.0)

So in effect, all texture coordinates (or any vertex attribute) are technically 4-dimensional. The function call above only supplies enough data for x and y, and GL fills-in the rest. Go ahead and think of these as 2D coordinates, because the rest of the vector is an identity.



来源:https://stackoverflow.com/questions/32025683/uv-coordinates-theoretical-questions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!