I have a varray full of triangles that make a large square. I’m trying to texture this large square and all i’m getting (it seems) is a one pixel column that is then stretched across the primitive.
I’m texturing each right angled triangle with UV coords (0,1), (0,0), (1,0) and (0,1), (1,1), (1,0) depending on which way up the triangle is.
rendering code.
glBindTexture(GL_TEXTURE_2D, m_texture.id());
//glEnableClientState(GL_INDEX_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//glIndexPointer(GL_INT, 0, &m_indices[0]);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData), &m_vertexData[0].x);
glNormalPointer(GL_FLOAT, sizeof(VertexData), &m_vertexData[0].nx);
glTexCoordPointer(2, GL_FLOAT, sizeof(UVData), &m_uvData[0].u);
glDrawElements(GL_TRIANGLES, m_indices.size(), GL_UNSIGNED_INT, &m_indices[0]);
glBindTexture(GL_TEXTURE_2D, 0);
texture is wrap mode is GL_CLAMP_TO_EDGE
EDIT
outputting the first two triangles i get values …
Triangle 1:
Indices(0,1,31)
Vertex0 (-15, 0, -15), Vertex1 (-15,0,-14), Vertex31 (-14, 0, -14)
UV (0,1), (0,0), (1,0)
Triangle 2:
Indices(0, 30, 31)
Vertex0(-15, 0, -15), Vertex30(-14, 0, -15) Vertex31 (-14, 0, -14)
UV (0, 1), (1, 1), (1, 0)
For posterity the full code is here
The two triangles make up a square with the diagonal cut from top left to bottom right.
Looks like you’re associating the UV data with the indices, not with the vertices. UV data is part of the vertex data, so you should probably pack it in the VertexData object, rather than keeping it separate. You can keep it separate, but you need one per vertex, not one per index.