PDA

View Full Version : glTexCoord coordinates

delic
10-06-2002, 12:29 PM
Ok I have a sphere and I have applied a texture to it but the texture is mapped to the wrong locations.. I want some given points of the 512x256 texture mapped to specific points on the sphere.

I believe that glTexCoord is the function for this but I am a little confused on what exactly are texture coords?? Say I want a given pixel (256,128)(in my texture bitmap pixel coords whose size is 512x256) to be mapped to some x,y,z global opengl coords.

do texture coords work like this:
would (256,,128) correlate to (.5,.5) in texture coords because 256/512=.5 and 128/256=.5 ??

As a summed up question how can I map pixel coords of my texture bitmap image to a given x,y,z point on a sphere???

[This message has been edited by delic (edited 10-06-2002).]

ioquan
10-06-2002, 09:02 PM
"do texture coords work like this:
would (256,,128) correlate to (.5,.5) in texture coords because 256/512=.5 and 128/256=.5 ??"

Yes, that is correct.

For your sphere, you are going to want one of the poles to have a 0.0 u texture coordinate, and the other to have a 1.0 u coordinate. The vertices in between should have evenly spaced u texture coordinates between 0.0 and 1.0. For the v coordinate, pick a meridian somewhere on the sphere to start, and then go around with evenly spaced coordinates between 0.0 and 1.0.

If you are using glDrawElements to draw your geometry (and you should be), there may be a few other things you need to take into consideration. In that case, you might want to actually have several vertices all exactly at the poles (because you will need different texture coordinates for them). You would also probably want to have two sets of vertices at your prime meridian, as one set will need a v coordinate of 0.0, and the other will need a v coordinate of 1.0.