且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何加载纹理到与OpenGL ES的一个圆

更新时间:2023-11-24 11:02:58

首先,你需要在你的texcoord阵列相同数量的texcoord对你有顶点的元组在你的顶点数组。

For starters, you need to have the same number of texcoord pairs in your texcoord array as you have vertex tuples in your vertex array.

它看起来像你刚刚得到了3对纹理坐标,和360的顶点。

It looks like you've just got 3 pairs of texture coordinates, and 360 vertices.

您需要有一个其中有360纹理坐标作为texcoord阵列。然后,当顶点被绘制,顶点[0]被texcoord [0],顶点[1]得到与texcoord配对[1],等等。

You need to have a texcoord array that has 360 texture coordinates in it. Then when the vertices are drawn, vertex[0] gets texcoord[0], vertex[1] gets paired with texcoord[1], etc.

===编辑===

您只需要定义以类似的方式纹理坐标你如何定义你的顶点:用数学公式在一个循环中。

You just have to define the texture coordinates in a similar manner to how you define your vertices: in a loop using mathematical formulas.

因此​​,例如,你的三角形扇的第一顶点是在该圆的中心。为了您的圆心,你想要的texcoord引用纹理的中心,这是坐标为(0.5,0.5)。

So for example, your first vertex of the triangle fan is at the center of the circle. For the center of your circle, you want the texcoord to reference the center of the texture, which is coordinate (0.5, 0.5).

当你走在边缘,只是觉得哪些纹理坐标映射到圆的那部分。所以,让我们假设你的下一个顶点是圆的最右边顶点,沿相同的Y值作为圆心所在。对于这一个texcoord将是(1.0,0.5),或纹理的上下中间的右边缘。

As you go around the edges, just think about which texture coordinate maps to that part of the circle. So lets assume that your next vertex is the rightmost vertex of the circle, that lies along the same y value as the center of the circle. The texcoord for this one would be (1.0, 0.5), or the right edge of the texture in the vertical middle.

圆的顶部顶点将具有texcoord(0.5,1.0),最左边的顶点是(0.0,0.5),等等。

The top vertex of the circle would have texcoord (0.5, 1.0), the leftmost vertex would be (0.0, 0.5), etc.

您可以使用您的三角填写顶点的其余部分。

You can use your trigonometry to fill in the rest of the vertices.