找到你要的答案

Q:Uv-Coordinates: Theoretical questions

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?

我得到的问题我有关于在OpenGL ES 2纹理的一些问题。在一些帮助下,这个问题得到了解决,但一些相关的问题已经出现:

  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?
answer1: 回答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.

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

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

如果你认为类似于另一个图形API(也许其中(0,0)是左上),这将不利于你的理解。

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

如果你说打电话glvertexattribpointer(…)你的纹理坐标,这是因为它们都是二维的。纹理坐标可以1,2,3或四维寻常,乍听。最常见的情况是2D,但3D和4D纹理坐标有自己专门的应用程序。

事实上,如果你打电话给glvertexattribpointer(…,2,…),顶点属性会自动扩展这样的GLSL:

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

所以实际上,所有的纹理坐标(或任何顶点属性)技术的四维。函数调用上面的x和y只提供足够的数据,和GL填补剩下的。继续把这些看成二维坐标,因为向量的其余部分是一个恒等式。

android  opengl-es  opengl-es-2.0