Problems texturing a cube

末鹿安然 提交于 2019-12-01 22:50:58

In OpenGL a vertex is the combination of a location and/or a texture coordinate and/or a colour and/or arbitrarily more attributes. So although you have 12 texture coordinates listed, all OpenGL gets from your data is 8 distinct vertices, each with a position and a texture coordinate.

Your right face is composed of two triangles, one with vertices 1, 5 and 3 and one with vertices 5, 7 and 3. So that's conceptually the same as a quad with vertices 1, 5, 7 and 3.

From your own data, that quad has vertices:

location: 1.0f, -1.0f,  1.0f; coordinate: 1.0f, 1.0f
location: 1.0f, -1.0f, -1.0f; coordinate: 1.0f, 1.0f
location: 1.0f,  1.0f, -1.0f; coordinate: 1.0f, 0.0f
location: 1.0f,  1.0f,  1.0f; coordinate: 1.0f, 0.0f

You'd therefore expect it to display the one dimensional straight line that runs along the right hand side of your texture, stretched out across the entire face. Is that what you're seeing?

If you want to supply unique texture coordinates for the corners of the side faces, you need to give them unique vertices (albeit that they'll be located exactly on top of other vertices).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!