0

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
tyuip
  • 157
  • 2
  • 10

1 Answers1

0

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.

Davido
  • 2,913
  • 24
  • 38
  • Hi. First of all, my problem is regarding Opengl ES 2. Sorry for being imprecise. But what I am really wondering about is the indices-part, there are 3 types of indices in an .obj file. Vertex-faces, Texture-coordinates-faces and normal-faces. To be able to map the textures correctly, I believe I must use the Texture-coordinates-faces as well. – tyuip Dec 01 '10 at 21:15
  • Yes, this is correct. If you map the vertex-texture coordinates when you initialize your object, it will come out correctly when you place a texture on it. If you've ever used a 3D animation package before, they have something called texture mapping. It basically tells each vertex what location in UV coordinates (0 to 1) it corresponds to for the image that is loaded onto those faces. If you texture map an object in a 3d package then export it as an obj file, the texture coordinates will make sure your image gets put in the rights spots. – Davido Dec 03 '10 at 20:28