Sign in to follow this  
MickeMan

Texture coordinates are mixed

Recommended Posts

Hello. I use the ASE file format and load my texture coordinates like this:
for(int v = 0; v < numtvertex; ++v, ++i)
{
	tmp = GetValueAfter("*MESH_TVERT", lines[i]);
	id = atoi(tmp.c_str());
	tmp = GetValueAfter(tmp, lines[i]);
	vUVC[v][0] = atof(tmp.c_str());
	tmp = GetValueAfter(tmp, lines[i]);
	vUVC[v][1] = atof(tmp.c_str());
}
And store them in my model class as GLfloat (*vUVCoords)[2]; The values are correct from the file and if the file defines 12 vertices with texture coordinates it stores them neatly inside our vUVCoords. Then comes the rendering with:
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, vUVCoords);
In the early days I loaded my meshes and didnt realise that the textures were all screwed up since I couldnt look at the mesh from diferent angles and only saw the faces where the texture looked perfect, some of you might remember me posting a screen dump of the earth rendered in my graphics engine, and it looked fine. I started thinking if maybe there's some fundamental concept of texture coordinates that I'm missing, and even tried to define texture coordinates per face (3*numvertex)[2] but that made every second face look wrong. After viewing through lots of tutorials I'm all confused and don't really know how glTexCoordPointer wants its array.

Share this post


Link to post
Share on other sites
I am a bit confused on what you are asking for sure, but the glTexCoordPointer() wants an array of texture coordinates based on what you setup the array to be. Meaning HOPEFULLY floats so

glTexCoordPointer(2, GL_FLOAT, 0, vUVCoords); so as long as vUVCoords is a pointer to an array of floats such as this

float vUVCoords[VERTEX_COUNT*2];

you should be fine.

I would drop the float vUVCoors[vertices][2] notation and use one large array. Just increment the elements as such


unsigned int index = 0;

for(int v = 0; v < numtvertex; ++v, ++i)

{

tmp = GetValueAfter("*MESH_TVERT", lines[i]);

id = atoi(tmp.c_str());

tmp = GetValueAfter(tmp, lines[i]);

vUVC[index++] = atof(tmp.c_str());

tmp = GetValueAfter(tmp, lines[i]);

vUVC[index++] = atof(tmp.c_str());

}


Share this post


Link to post
Share on other sites
I changed the vUVCoord pointer to be just a pointer with the length of numtvertex*2 but the result stays the same.

Lets simplify things a bit so that my question is clear.

I load a box that has 12 faces and 8 vertices.
In the mesh file 12 meshtvertices are defined. I load these 12 vertices into an array of GLfloats, thats 24 uv values, like: 1.000, 0.000, 0.000, 1.000 and so on.

Doing these steps results in faulty UV coordinate definitions for our box and im guessing that I need to define more UV coordinates per face. A face should have 3 UV coordinates, and since we have 12 faces that adds up to 36 uv coordinates. I thought that only defining our vertex uv coordinates would be enough, but I'm obviously wrong. I will try mapping the coordinates per face and see if that is the error.

Share this post


Link to post
Share on other sites
Well if you have 12 faces, which are using GL_TRIANGLES then you would have 36 vertices total. So 36*2 = 72 texture coordinates. You should step through the code when it is loading and see if your variables show the correct values are being loaded?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this