Rookie
Rookie

Reputation: 3793

gluCylinder() and texture coordinates offset / multiplier?

How can i set the texture coordinate offset and multiplier for the gluCylinder() and gluDisk() etc. functions?

So if normally the texture would start at point 0, i would like to set it start at point 0.6 or 3.2 etc. by multiplier i mean the texture would either get bigger or smaller.

The solution cant be glScalef() because 1) im using normals, 2) i want to adjust the texture start position as well.

Upvotes: 4

Views: 1562

Answers (2)

Christian Rau
Christian Rau

Reputation: 45948

The solution has nothing to do with the GLU functions and is indeed glScalef (and glTranslatef for the offset adjustment), but applying it to the texture matrix (assuming you don't use shaders). The texture matrix, selected by calling glMatrixMode with GL_TEXTURE, transforms the vertices' texture coordinates before they are interpolated and used to access the texture (no matter how these texture coordinates are computed, in this case by GLU, which just computes them on the CPU and calls glTexCoord2f).

So to let the texture start at (0.1,0.2) (in texture space, of course) and make it 2 times as large, you just call:

glMatrixMode(GL_TEXTURE);
glTranslatef(0.1f, 0.2f, 0.0f);
glScalef(0.5f, 0.5f, 1.0f);

before calling gluCylinder. But be sure to revert these changes afterwards (probably wrapping it between glPush/PopMatrix).

But if you want to change the texture coordinates based on the world space coordinates, this might involve some more computation. And of course you can also use a vertex shader to have complete control over the texture coordinate generation.

Upvotes: 1

genpfault
genpfault

Reputation: 52082

Try using the texture matrix stack:

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.6f, 3.2f, 0.0f);
glScalef(2.0f, 2.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
drawObject();

Upvotes: 1

Related Questions