I have already calculated the texture coords for everything. After mapping them, though, OpenGL doesn't draw the textures "correctly" (hehe...). Here's the code I'm using to calculate the texture coordinates for each vertex:
void SetTextureCoords(TPolygon * p){float lowest = p->v[0].x, highest = p->v[0].x, range = 0, offset = 0;for(int j = 0; j < 4; j++) { if(p->v[j].x < lowest) lowest = p->v[j].x; if(p->v[j].x > highest) highest = p->v[j].x; }range = (lowest - highest) * -1;offset = 0 - lowest;int abspos;for(int j = 0; j < 4; j++) { abspos = p->v[j].x + offset; if(range) p->u.push_back((float)abspos / (float)range); else p->u.push_back(0); }//...//Repeat for y and z coordinates of the poly to calculate v and w, respectively//...}
As I figure it, I need to calculate the texture coordinates in three dimensions because if I only used the
XY
plane, I'd get wrong results if the polygon didn't lie on the same plane.
I know there's somthing wrong with this - I just don't know what.
For example, using the above method, mapping every polygon that isn't on the YZ plane is texture mapped correctly (if I use
glTexCoord2f(p->v[j], p->u[j])
), everything else is all messed up.
v
in TPolygon is a vector of structs called TVector (standard structure),
u
,
v
and
w
are vectors of floats each.
thanks - more help needed though

crispy
EDIT: darn tags...
[edited by - crispy on May 4, 2002 7:28:36 AM]
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared