0
votes

When parsing an .obj-file, with vertices and vertex-faces, it is easy to pass the vertices to the shader and the use glDrawElements using the vertex-faces.

When parsing an .obj-file, with vertices and texture-coordinates, another type of face occur: texture-coordinate faces.

When displaying textures, apart from loading images, binding them and passing texture coordinates into the parser, how to use the texture-coordinate faces? They differ from the vertex-faces and I suppose that the texture-coordinate faces have a purpose when displaying textures?

Regards Niclas

1

1 Answers

0
votes

Not sure what you're asking, but if I understand you correctly, you're wondering how do you store the data for texture coordinates to render a textured 3d object. If so, you store your vertex-normal-textureCoordinate data in an interleaved format, like below:

vertexX vertexY vertexZ normalX normalY normalZ textureX textureY textureZ

once you have an array of these, you then create pointers to the different parts of the array and render like below:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[0]);
glNormalPointer(3, GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[3]);
glTexCoordPointer(GL_FLOAT, sizeof(vertexArray[0])*9, &vertexArray[6]);

glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, &indices[0]);

At least that is how I'm doing it. There may be a better way, and if there is, I'd be glad to know.