PDA

View Full Version : Texture coordinates ? ( on .x model )



honny
04-27-2003, 04:16 AM
im trying to load and render a model with ogl.
well the model its a simple directx .x file.

simple because it is only 1 static mesh.

in my code i have writed a loader for x models, at the moment all what i need are vertex + textures coordinates.

i render it like like a simple directx mesh, but the texture coordinates are wrong.

for example if u look at this image you see on the left (black background) the right model , it display "MP" correctly.
on the right it is my scene( blue background ) and it display "PM", like in a mirror,
image:
http://space.tin.it/clubnet/aglare/textureerror.jpg

at the moment my main code ( where im suspicious to have an error ) is here :
this piece is for render a model, look at the line:
"glTexCoord2f(x,-y);"
i really think the error is here "-y" ,



for(i=0;i<nfaces;i++)
{
glBegin (GL_POLYGON);
for(j=0;j<faces[i].nfacesvertexindex;j++
{
a=vertices[ faces[i].facesvertexindex[j] ].x;
b=vertices[ faces[i].facesvertexindex[j] ].y;
c=vertices[ faces[i].facesvertexindex[j] ].z;
x=texturecoords[faces[i].facesvertexindex[j]].u;

y=texturecoords[faces[i].facesvertexindex[j]].v;
/*error here i think /e' giusto -y ?*/
glTexCoord2f(x,-y);
printf("texture : %f %f\n",x,y); glVertex3f (a,b,c);
printf("vertici : %f %f %f\n",a,b,c);
};
glEnd();
};


thx in advance

PS:do you know where i found the model ? ( great game !!!)


[This message has been edited by honny (edited 04-27-2003).]

honny
04-29-2003, 11:48 PM
do i must ask this on advanced forum ?

shinpaughp
04-30-2003, 12:04 PM
Have you tried glTexCoord2f(x, y) or (y,x) or (-y, -x), or better yet (x, 1-y) or (1-x,y)? Or have you looked at the data in your file to see what kind of values are there? If you do, you may get some idea as to what is needed.

honny
05-01-2003, 01:50 AM
thanks , i have already tried that but it doesnt have any effect.
anyway if i try to use (x,y),(-x,y) etc... the texture are ALL messed up and not like in a mirror.

the textures coordinates are standard dx coordinates ( u,v ).

shinpaughp
05-01-2003, 06:38 AM
Then you probably didn't TRY hard enough.

If you currently have x, -y and your texture appears to be reversed in the x direction... hmmm, have you tried 1-x,-y or -x, -y or looked at the values in your file to determine the range and make an educated guess as to what it could be using basic algebra? Hint: for non-repeating textures, the tex coords are typically between 0 and 1.

honny
05-01-2003, 07:11 AM
the texcoords like u can imagine are all 1>x>0 and like i have writed in prec post i have tried all x/y couples coordinate ( i was think about an error in my dx exporter ) .
have you never worked on dx files ?
maybe my error is how to interpretate the u,v of .x templates.

shinpaughp
05-01-2003, 07:56 AM
Originally posted by honny:
the texcoords like u can imagine are all 1>x>0 and like i have writed in prec post i have tried all x/y couples coordinate ( i was think about an error in my dx exporter ) .
have you never worked on dx files ?
maybe my error is how to interpretate the u,v of .x templates.

If all the u,v coords are 0<x<1 then to reverse you use 1-x or 1-y or both if necessary.

If that does not work, and you really really want, email me your code along with the .x file (preferably compressed together in a common format like zip) and I will look at it and try to fix the tex coord problem for you. Without more info there is not much anyone can do.

honny
05-02-2003, 01:12 AM
thanks !!!
you are a really nice person and your help is really appreciated.
i will send you my little work in progress only to show you what im doing.
but i prefer to rewrite myself another time this bugged code.
thx anyway.