Problems texturing a cube

前端 未结 1 1746
谎友^
谎友^ 2021-01-21 15:52

im trying to make a cube with a different texture on each face.

I have the front face and the rear face working now. Now i am trying to make the right face of the cube.

1条回答
  •  温柔的废话
    2021-01-21 16:51

    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).

    0 讨论(0)
提交回复
热议问题