9

So here's the question: what do the values of texture coordinates represent? For example, in my obj file, texture coordinates look like these:

vt 0.474178 0.050139
vt 0.477308 0.050139
vt 0.480438 0.050139
vt 0.483568 0.050139

The size of my texture (bmp file) is 640*360. Does that mean (0.474178, 0.050139) in the obj file correspond to the (0.474178*640, 0.050139*360) point in the bmp file? That is, texture coordinates indicate the point position in bmp file by doing:

 u*width_of_the_bmp,  v*height_of_the_bmp

And if I'm wrong, how can I get the corresponding correlation between vt and bmp point position? Because I want to get the RGB values for every vertex, and I can get the RGB values for every pixel in the bmp file, how to link these data together to get what I want?

lilliam.C
  • 107
  • 1
  • 9
  • If this is really about OpenGL, then the interpolation of the uv-coordiantes is done automatically between vertex and fragment shader stage. Just make sure to lookup the texture in the fragment shader. – BDL Jul 14 '16 at 09:55
  • 1
    http://stackoverflow.com/a/5532670/4285290 worth to read. – eldo Jul 14 '16 at 13:07

1 Answers1

9

That is correct.

Usually, texture coordinate 0,0 is pixel coordinate 0,0, and texture coordinate 1,1 is the opposite corner. Texture coordinates greater than 1 wrap around the texture, so if you go from 0,0 to 2,0, you go around the texture twice.

Of course, some programs might interpret them differently. There's no rule that it must be this way, but it usually is the case.

user253751
  • 57,427
  • 7
  • 48
  • 90
  • Thanks a lot! But there's still a question. Taking the pixel points in bmp as a matrix, we can get a 640*360 matrix. We can refer to a point like (10, 1) in this matrix, but (10.5, 1.4) seems impossible. However, when multiplying the vt coordinates with the height/width of the bmp file, it's hard to get a integer, so rounding the result may be the case? – lilliam.C Jul 15 '16 at 07:55
  • @lilliam.C Those will either be rounded, or interpolated, depending on what texture mode the program uses. – user253751 Jul 15 '16 at 08:18