4

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.

Rookie
  • 3,753
  • 5
  • 33
  • 33

2 Answers2

1

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();
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • shouldnt it be glScalef(2.0f, 2.0f, 2.0f) ? or does the Z matter only if im using 3d textures? however, i set the Z coord to my multiplier as well, didnt see any problems from it. – Rookie Aug 27 '11 at 00:34
  • Yeah, I'm pretty sure you only need a non-1.0 Z scale if you're doing 3D textures, or *very* unusual 2D stuff. – genpfault Aug 27 '11 at 03:48
  • @Rookie And keep in mind that doubling the texture coordinates halfes the size of the texture image on the object. – Christian Rau Aug 27 '11 at 12:42
1

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.

Christian Rau
  • 45,360
  • 10
  • 108
  • 185