Sign in to follow this  

small texture on large torus

Recommended Posts

hi all. i've a problem with mapping a small texture onto a rather large torus. i think my main problem is how i try to automatically assign texturecoords. i'm not very experienced with textures, and the result is a lot of extremely small textures on the torus, and for some reason it is coloured all red as well (the texture is some grey rock). after loading (using a TGAloader) and binding my texture i do this: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); thank you in advance. /s a i m i (edit: spelling)

Share this post

Link to post
Share on other sites
To understand what's going on, you need to understand how OpenGL's automatic texture generation works. The object linear generation function is just the dot product of the vertex' position in object coordinates and the object plane vector p, which is specified with glTexGen*
g = p1xo + p2yo + p3zo + p4wo
where g is the generated texture coordinate. The default values for the object plane vectors are [1,0,0,0] and [0,1,0,0] for the s and t coordinates, respectively. Since you don't show any code specifying those values I'll assume they are the defaults in the following example.

Let's say your torus is lying flat on the x-y plane, has an outer diameter of 1000, and is centered at the origin in object coordinates. This means the x and y components of its vertices will be in the range [-500,500]. If we look at the s coordinate generation for the maximum x value we get
s = 1xo + 0yo + 0zo + 0wo = xo = 500
Similarly the minimum generated s coordinate will be -500. Working through the calculations for the t coordinate shows it to be in the same range (since y was in the same range as x). So the texture coordinates are also in the range [-500,500].

Normalized texture coordinates are in the range [0,1] and since you set the texture's wrap modes to GL_REPEAT, if the texture coordinates go outside that normalized range, it will repeat. Since your texture coordinates are in the range [-500,500], it will repeat across the torus 1000 times.

There are a few possible ways to change this. You can create the torus so that its vertices are in a smaller range and then multiply the modelview matrix by a scaling matrix before rendering it, pass different object plane values to glTexGen*, or set the texture matrix to a scaling matrix before rendering the torus. I wouldn't recommend the first option because it has other effects (although not noticeable if this is all you are doing) than just altering the texture coordinates.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this