View Full Version : opengl glTexGen() question
04-02-2006, 08:57 PM
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
04-03-2006, 02:59 AM
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.
glScalef(1.0f / (float) width, 1.0f / (float) height, 1.0f);
04-03-2006, 03:05 AM
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 = a*x + b*y + c*z + d*w, 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.
04-03-2006, 06:15 AM
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.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.