Assuming that you have the same edition of the book as I do (1.4), then look on page 361. The picture on the left is the texture with the texture coordinates (glTexCoord) that are used superimposed on top. The picture on the left is the the final drawn object using glVertex. It is a different shape than the coordinates taken from the texture so the texture must be stretched to fit.

If that didn't make sense, think of it this way, the glVertex3f gives the position of the vertex in the world, and glTexCoord tells opengl what place in the texture to pin onto it. (textures are very stretchy) In this case, the 3f on glVertex3f means that you are defining a vertex in 3D space using a float parameter, and the 2f on glTexCoord2f means that you are using a float to specify a 2D position on the texture.

I've only done a little bit of texture coding in OpenGL. If you didn't already know, the texture coords used in glTexCoord2f() are in a range of 0.0f and 1.0f. So if you have a 256x256 texture (that's the dimensions in pixels) 1.0f, 1.0f would be the lower right corner of the image.

I have found that: 1 / x * n gives me the right value to pass to glTexCoord2f().
x = the width or height of the texture in pixels.
n = the 2D pixel coord you want.

Vertizor Wrote:I've only done a little bit of texture coding in OpenGL. If you didn't already know, the texture coords used in glTexCoord2f() are in a range of 0.0f and 1.0f. So if you have a 256x256 texture (that's the dimensions in pixels) 1.0f, 1.0f would be the lower right corner of the image.

I have found that: 1 / x * n gives me the right value to pass to glTexCoord2f().
x = the width or height of the texture in pixels.
n = the 2D pixel coord you want.

The result is the texture coord in OpenGL space.

If you use the integer versions of glTexCoordi*() it will do the same thing with less effort. Very convenient for 2D graphics. However, if you want sub-pixel coordinates (not very useful in most cases) you'll still have to use your version.

Skorche Wrote:If you use the integer versions of glTexCoordi*() it will do the same thing with less effort. Very convenient for 2D graphics. However, if you want sub-pixel coordinates (not very useful in most cases) you'll still have to use your version.

Actually, I think I read somewhere that the PowerPC does floating point just as fast as integer so I'm not sure it would actually make that much of a difference.

Also there is an extension, GL_TEXTURE_RECTANGLE_EXT, that allows you to use non-square, and non-power-of-2 textures. But in this mode, instead of using texels between 0.0 and 1.0, you actually have to specify texture coordinates. Therefore, if you were trying to map a 450 x 321 pixel texture map on to a unit square you'd have to specify