# Q：UV坐标：理论问题

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. 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?

### 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.

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

（0,0）映射到一个纹理图像的左下角。

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

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

android  opengl-es  opengl-es-2.0