View Full Version : Keep auto generated tex coords within [0.0, 1.0]?

10-01-2004, 07:36 AM
When I render complicated 3D models in OpenGL I use automatic texture coords generation for s,t. In manual case to apply complete texture to object we keep tex coords within [0.0,1.0]. How to keep them within this range in automatic tex coords generation mode? (Its ugly, for a fixed texture, changing 3d model size you get from just a small tex part sticked to it or for bigger sized models the texture becomes repeated all over them)?

10-01-2004, 07:56 AM
Have you tried using the texture coordinate transformation matrix?

10-01-2004, 11:15 PM
No I havent. What is this and how to apply it.
I just do simple texture loading and enable automatic texture coord generation for GL_S, GL_T
supplying appropriate plane equations.
... then render 3d model.

10-02-2004, 12:36 AM

10-02-2004, 04:56 PM
Dorbie's suggestion (which is also endash's suggestion) will work.

However, you can do this yourself by just modifying the planes you put in for texgen.

The plane is a normal (A,B,C) and distance (D). If the diameter of your objects' bounding radius is X, you want to scale the normal by 1/X. You then should calculate the minimum point Y of your model WRT the (normalized) normal's direction, and set D to -Y. If your model is centered at the origin, the value of Y is your model's radius.

Do this to the values for each of the planes you have, before you give them to GL, and all will be well.

10-03-2004, 10:13 PM
Yet a problrm with palnes equations for glTexGen().
Supposing a 2D texture and GL_S GL_T enabled and given an arbitrary shaped model centered at the origin.
1. Applying splane[] = {1.0,0.0,0.0,0.0}
tplane[] = {0.0,1.0,0.0,0.0}
we get texture generation for face and back of the model, hence from sides, top and bottom it looks very ugly.
2. Applying splane[] = {1.0,0.0,0.0,0.0}
tplane[] = {0.0,0.0,1.0,0.0}
we get texture generation for top and bottom of the model, hence from face, back and sides it again looks very ugly.
...and so on
There are no problems if I have surface patch with hight on Y axis then applying 2. equations the texture perfectly applyed on top (its all we need).
But if 3D model of the arbitrary shape (similar to a shpere or cube or conus) how to get simultaneous texture generation for face and back, sides, top and bottom?

10-04-2004, 12:36 AM
If your model is convex, you'll be better of using cube-maps or sphere-mapping. If it's not, and you still want to use the automatic texcoord generation you could split your model in various patches based on the normal direction of each triangle and/or occlusions and apply different texgen planes for each patch.