Texture Coordinate Generation with glTexGen

I’m reading through “Beginning OpenGL Game Programming by Astle and Hawkins,” and I’ve made it almost all the way through. I am suddenly finding myself confused over texture coordinates.

Early in the book, it says that textures coordinates are: topleft (1.0,0.0), topright (1.0,1.0), bottomright (1.0,0.0), bottomleft (0.0, 0.0). If this is true, exactly what is being generated by glTexGen(GL_TEXTURE_GEN_MODE,…)?

glTexGen is a special texture mapping generation function. For 99% of the thing you render you specify the texture coordinates your self; as you have said for the textured quad example.
However, there are cases when you don’t have the texture coordinates and GL can generate them for you. Such cases include sphere mapping, cube mapping, normal mapping and other such effects. Open GL has these modes known as eye-linear or object-linear. What this is refering to is how GL is internally calulating the auto-generated texture coordinate from the incomming vertex position (whether GL does this in eye space or object/world space).
Anyway, no need to worry about it for your regular day-to-day encounters with OpenGL.

I’m afraid I’m still a bit confused over this. . . From what I’ve read, this is my understanding:

The topright pixel of the texture is DEFINED as 1.0, 1.0. The bottomright pixel is DEFINED as 1.0,0.0. The bottomleft is DEFINED as 0.0 , 0.0. And the topleft is DEFINED as 0.0 , 1,0.

(My understanding is obviously not correct, which is leading to some confusion)

Anyway, based on this understanding, I don’t understand what’s being generated. It’s like saying glGenOriginofaGraph(…). Such as function shouldn’t even need parameters. It should return 0,0 always. So why bother?

Is the above scheme (1.0,1.0. . . 1.0,0.0. . .etc.) the default? Are we generating a different scheme?

If 99% of the things I render I have to specify myself, then why do I not need to worry about this for regular day-to-day encounters? I’m confused. :frowning:

Perhaps what I’m trying to ask is this:

Does this function(s) specify a coordinate SYSTEM? Or is this generating the pixels themselves?

The topright pixel of the texture is DEFINED as 1.0, 1.0. The bottomright pixel is DEFINED as 1.0,0.0. The bottomleft is DEFINED as 0.0 , 0.0. And the topleft is DEFINED as 0.0 , 1,0.

No. The location of the top-left pixel of the texture (pixels of textures are often called “texels”) is (1, 0). Much like the location of the top-right pixel on your screen is (0, 0).

A texture coordinate is a value used to specify a location on a texture. Texture coordinates usually are on the range [0, 1]. The actual value of any particular coordinate depends on the contents of the texture itself.

Perhaps one texture has black under [0.5, 0.5]. Another texture may have a green pixel there. Another texture may be mauve. Texture coordinates specify location, not content.

In typical graphics usage, you map a texture onto a triangle by specifying texture coordinates at each of the three vertices of the triangle. This effectively selects a region from the texture and puts it on the triangle. This is called “texture mapping”: you are mapping a 3D surface (the triangle) to a 2D texture (via the triangles texture coordinates).

Now, how you specify these texture coordinates is up to you. The traditional way is to just have them as part of your vertex data. What texture coordinate generation does is create a texture coordinate for a vertex based on various functions. glTexGen is a way of creating a mapping between a texture and a triangle; the texture coordinate generation functions are all different mapping techniques.

I think I understand. . . The texture remains in memory as a 2D rectangular array, but the coordinate function determines how this gets mapped onto the polygon. It’s like a tranformation from cartesian to spherical or cylinderical or some other u,v,w coordinate space, correct? If so, is the default a basic linear mapping?

(Thank you for all your responses, btw)