opengl glTexGen() question

When I use glTexGen, i’m using a bitmap that is kind of small and it is tiling it over the polygon instead of stretching it over the polygon. I tried using GL_CLAMP but to no avail, it just looks weird. It’s like gltexgen keeps making all these tex coor greater than 1 and it just repeats. Any tips on how to use it to stretch the image?? Thx in advance for the help

-Jared

Depending on your TexGen mode, you might want to apply a texture matrix to adjust the final texture coordinates.
E.g. something like this would scale 2D texture coordinates in the range width and height down to the 0.0 to 1.0 range.
What width and height are depends on your texgen mode and rendering setup.

glMatrixMode(GL_TEXTURE); // per texture unit.
glLoadIdentity();
glScalef(1.0f / (float) width, 1.0f / (float) height, 1.0f);

glTexGen produces texture coordinates by using the vertex coordinates as input for a texture coordinate generation function. In case of modes GL_EYE_LINEAR and GL_OBJECT_LINEAR, you can modify that function by providing parameters for GL_EYE_PLANE or GL_OBJECT_PLANE.

For both modes, the generation function is g = ax + by + cz + dw, where (x, y, z, w) is the vertex coordinate (transformed by the current modelview matrix in case of EYE_LINEAR), and (a, b, c, d) are the parameters specified for GL_EYE_PLANE or GL_OBJECT_PLANE (for EYE_PLANE, the paramters are multiplied by the inverse modelview matrix at the time of the glTexGen call).

In short, you can choose the scale of the generated texture coordinates yourself, by providing appropriate parameters for either GL_OBJECT_PLANE or GL_EYE_PLANE.

For example, you can scale the texture by inversely scaling the paramters for the right plane. If you want your texture twice as big as it is currently, halve the plane parameters (the initial values are (1,0,0,0) for GL_S, (0,1,0,0) for GL_T, and (0,0,0,0) for GL_R and GL_Q).

You can move the generated texture coordinates by changing the fourth parameter of the plane.

If you don’t use a very old graphics card, then it is probably easier to use/learn vertex shaders instead. Learning glTexGen is in that case not worth the hassle.