Texture Mapping & Texture Coordinates

I have texture coordinate arrays and vertex arrays. I try to load them in CPP&opengl.
Object is ok geometrically. Texture is .tga file. But there are some problems with texture coordinates, because .tga(512x512) picture is strange on texture. I think there is a problem with texture coordinates.

Texture coordinate array dimension is more than vertex array.

I use following functions.

glTexCoord2f…
glVertex3fv…

Can texture coordinate array dimension be more than vertex? How will I use them? Should vertex array index and texture array index be equal to each other?

You can only have one set of texture coordinates per vertex. Anything else wouldn’t make sense.

As for specifically which texture coordinates go with which vertices, that’s something you’ll have to decide based on your use-case.

Since the texture lies on a plane, meshes need to be unfolded.

By doing so, the number of geometry faces is the same as the number of texture faces, but the number of texture vertices may be greater than the number of 3D vertices since the mesh is cut.

Since you have the correspondance between texture faces and 3D faces, you can render them using the indices of the texture vertices and of the 3D vertices.

I have texture coordinate array, texture index array, vertex coordinate array, vertex index array already.
I use same index to reach index arrays, and then I reach texture index array and vertex index array and then I reach texture coordinates and vertex coordinate arrays.

But object texture mapping is missing for some part of objects. Some part is OK.

How will I render for fallowing pseudo code and how will I use vertex index and vertex coordinate arrays, texture index and texture coordinate arrays together ?

Pseudo Code
TextureCoordinates [][]=…
TextureIndex=[]
VertexCoordinates[][]=…
VertexIndex=[]

for i…1t o N {
glTexCoord2f(TextureCoordinates[TextureIndex[i]][0],TextureCoordinates[TextureIndex[i]][1]);
glVertex3fv(VertexCoordinates[VertexIndex=[i]];
}

You cannot do that.
You need to make the loop over the faces:

Pseudo code for immediate mode:

int va, vb, vc, tca, tcb, tcc;
for (int i = 0; i < nbFaces; ++i) {
   getNthFace(i, &va, &vb, &vc); // assuming faces are triangles
   getNthTextureFace(i, &tca, &tcb, &tcc); // idem

   glTexCoord2f(TextureCoordinates[tca][0], TextureCoordinates[tca][1]);
   glVertex3fv(&VertexCoordinates[3*va]);

   glTexCoord2f(TextureCoordinates[tcb][0], TextureCoordinates[tcb][1]);
   glVertex3fv(&VertexCoordinates[3*vb]);

   glTexCoord2f(TextureCoordinates[tcc][0], TextureCoordinates[tcc][1]);
   glVertex3fv(&VertexCoordinates[3*vc]);
}

But, if I remove glTexCoord2f, if I don’t use texture then object shape is rendered correctly with this code. Just texture doesn’t run.

Following code runs correctly. Object is OK.
But, texture is not OK.

VertexCoordinates[][]=…
VertexIndex=[]

for i…1t o N {
glVertex3fv(VertexCoordinates[VertexIndex=[i]];
}

How will texture coordinated be used?

Is it about dimensions of .tga(512*512)?
Because some part of object are covered with the texture. But some part of object is blank.

Maybe object size is big for .tga ???

Texture coordinates have nothing to do with the texture size.
Except for GL_TEXTURE_RECTANGLE, they are normalized, meaning they are between 0 and 1, independently of the texture resolution.
The texture could be 512x512, 128x1024, or anything else, the texture coordinates would stay between 0 and 1.

If your rendering work by using the vertex in the order they appear instead of using the faces, you are lucky they appear in the same order as they would by looping over the faces.

I use faces already.
I use vertex indexes and texture indexes to reach vertex and texture coordinates.
Vertex coordinates are OK. But texture is not OK
???

senem, I’m not sure you are listening. Your code loops over vertices and not faces. They are two different things. Your code is not correct, that is why “if I don’t use texture then object shape is rendered correctly with this code. Just texture doesn’t run.”

Change your code. Try sharp_pixel’s example.

But I use vertex arrays to reach vertice coordinates.
It is triangle. Three vertex index on vertex array in order defines a face. So I think it should be correct.

If face is different thing, how will I get a face from vertice index array and vertice coordinate array?

Maybe you should post your whole code… We are not getting anywhere like this. What format is this model in for example (I don’t see you mentioning it)?

I use 3ds max vrml 2.0 coordinates :
Rendering object is correct. But texture mapping runs for some part of object correctly, for some part of object, texture is missing. Some part of object is not covered with texture picture.
There is something wrong matching texture&vertex indexes and coordinates.

???

GLfloat Coordinate [][3] ={{5.09517,8.73457,0},xxx…,{9999,9999,9999}};
short coordIndex []= {6, 1, 0, -1, …,9999};
short TextureIndex []= {6, 1, 0, -1,…,9999};
GLfloat TextureCoordinate [][2] = {{2,2},
{2,1.975},…,{9999,9999}};
Render :
glBegin (GL_TRIANGLES);
while(coordIndex[intCoordIndex]!=9999)
{
int vi=coordIndex[intCoordIndex];
int ni=normalIndex[intCoordIndex];
int ti=TextureIndex[intCoordIndex];
if (ni!=9999&ni>=0){ glNormal3fv(&Normal[ni][0]);};
if(vi>=0){
glTexCoord2f(TextureCoordinate[ti][0],TextureCoordinate[ti][1]);
glVertex3fv(&Coordinate[vi][0]);
}
++intCoordIndex;
};
glEnd ();
glEndList();

And this code runs for torus, sphere, box objects for texturing. I tried for all of them. Texture is ok for them.
Texture mapping doesn’t run for teapot body. (It runs teapot funnel, teapot cover part, but it doesn’t run for just teapot body.) But vertex side is correct for all teapot parts. Rendering object is OK. But texturing doesn’t OK.
???

In this case you teapot model data is probably wrong. Could you try more objects?

I tried lots of objects.
Torus, sphere, box are OK. They are rendered with texture.
I am sure teapot coordinates are OK. Because I tried it much with different teapots.
But teopot and a head model aren’t rendered with texture correctly.
Maybe more complicated objects aren’t rendered correctly. If the object contains complicated polygons, then it is not rendered with texture.
Without texture, all of them are ok.
I cannot understand relationship between vertex and texture coordinates.
? ? ?

I get the feeling senem isn’t going to blink anytime soon. :smiley:

Is there really nothing better to discuss than this? I don’t know whether I should offer technical advice or youth guidance counseling.

Maybe it is because of texture parameter settings.
Because some parts are rendered with texture correctly. Some parts are marked with lines, some parts are blank.
It depends on object polygon style.

Check for any openGL errors. It might give you a clue to any gl commands that are ignored during rendering.
Don’t know if it helps.
Oh, and that glEndList() at the end of your code looks a bit suspicious…