本文介绍了UV-坐标:理论问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的我有一些问题关于OpenGL ES 2.0的纹理​​。随着一些帮助这个问题现在已经解决了,但一些相关的问题出现:


  1. 我怎么知道wheather UV坐标和顶点坐标结合在一起?我认为有顶点和紫外光之间的双射,例如(0,0)顶点为(0,0)紫外线,和(宽度,0)的顶点的至(1,0),和(0,高度)UV的顶点(0,1)的。但是,由于纹理会出现在我的例子翻转,本以为可能是错误的?

  2. 我怎么能知道 glVertexAttribPointer 方法的第二个参数?我为什么要设置2在这种情况下?


解决方案

子弹1点听起来就像是关系到GL纹理原点。

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

如果您已经假设类似于另一个图形API(说不定其中(0,0)是左上角)的东西,这将不利于您的理解。

子弹点2,假设它是纹理坐标,定义了2D COORDS。

如果你正在谈论调用 glVertexAttribPointer(...)您的纹理坐标,那是因为他们是2维的。纹理坐标可以1,2,3或4维的不寻常,因为这听起来可能在第一。最常见的用例是2D的,但3D和4D纹理坐标有自己的专门的应用程序。

在事实上,如果你调用 glVertexAttribPointer(...,2,...),顶点属性被自动GLSL扩大是这样的:

  VEC2(X,Y)==> vec4(X,Y,0.0,1.0)

因此​​,在实际上,所有的纹理坐标(或任何顶点属性)在技术上是4维。函数调用以上只对x和y提供足够的数据,和GL填充式的其余部分。来吧,想到这些作为二维坐标,因为载体的其余部分的标识。

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?
解决方案

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.

这篇关于UV-坐标:理论问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:13