如何在没有GL_REPEAT的情况下将精灵包裹在立方体周围? [英] How do I wrap a sprite around a cube without GL_REPEAT?
问题描述
我正在使用OpenGL 3.2+.我创建了一个由8个顶点组成的多维数据集VBO(每个顶点包含8个浮点数:x,y,z,r,g,b,s,t),一个EBO为该多维数据集创建面,以及一个VAO将其全部绑定在一起.
I'm using OpenGL 3.2+. I created a cube VBO of 8 verticies (each vertex consists of 8 floats: x,y,z,r,g,b,s,t), an EBO to create the faces for that cube, and a VAO to tie it all together.
我有一个由数百个16x16子画面组成的子画面图集.我正在尝试从该地图集中获得1个精灵,使其出现在立方体的所有侧面(任何方向都可以).
I have a sprite atlas consisting of hundreds of 16x16 sprites. I'm trying to get 1 sprite from that atlas to appear on all sides of the cube (any orientation is fine).
通过调整"s,t"参数,我可以使6张脸中的4张可以工作,但是我似乎无法让最后2张脸显示除随机垃圾之外的任何东西.
By tweaking the "s,t" parameters, I can get 4 of the 6 faces to work, but I can't seem to get the last 2 faces to show anything other than random garbage.
我需要修改我的着色器以在地图集上执行某种自定义UV包装吗?
Do I need to modify my shader to perform some kind of custom UV wrapping on the atlas?
推荐答案
通过调整"s,t"参数,我可以使6张脸中的4张可以工作,但是我似乎无法让最后2张脸显示除随机垃圾之外的任何东西.
By tweaking the "s,t" parameters, I can get 4 of the 6 faces to work, but I can't seem to get the last 2 faces to show anything other than random garbage.
至少必须对多维数据集的2条边使用单独的顶点和属性.这意味着您至少需要8 + 2 * 2 = 12个不同的顶点属性集.
At least you have to use separate vertices and attributes, for 2 edges of the cube. This means you need at least 8+2*2=12 different sets of vertex attributes.
x y z u v
0 : -1 1 1 0 0
1 : 1 1 1 1 0
2 : -1 -1 1 0 1
3 : 1 -1 1 1 1
4 : -1 -1 -1 0 0
5 : 1 -1 -1 1 0
6 : -1 1 -1 0 1
7 : 1 1 -1 1 1
8 : -1 1 1 1 1
9 : -1 1 -1 1 0
10 : 1 1 1 0 1
11 : 1 1 -1 0 0
请注意,索引属性为0、2、4和6的顶点属性集具有相同的u坐标0.索引属性为1、3、5和7的顶点属性集具有相同的u坐标.1.
如果要将纹理包装到四边形,则必须更改u和v坐标.因此,您必须添加单独的顶点属性集8、9、10和11.
Note, the vertex attribute sets with the indices 0, 2, 4 and 6 have an identically u-coordinate of 0. And the vertex attribute sets with the indices 1, 3, 5 and 7 have an identically u-coordinate of 1.
If you want to wrap a texture to a quad you have to vary the u and the v coordinates. Because of that you have to add the separated vertex attribute sets 8, 9, 10 and 11.
注意,如果要添加垂直于立方体侧面的法线向量,则需要24个顶点属性集.立方体的每一侧为4.
这篇关于如何在没有GL_REPEAT的情况下将精灵包裹在立方体周围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!