Hi…
I’m trying to learn about applying textures to quadrics. I’ve almost got them working correctly, but I’ve run into a problem I just can’t get past.
I’m trying to create a rotating sphere with a texture – for example, a spinning planet.
When I apply a texture to a sphere drawn by gluSphere and then rotate the sphere, the texture doesn’t rotate. I know the sphere is rotating – if I draw it with the drawing style set to GLU_LINE, the lines move. The resulting object shows the same portion of the texture no matter what rotation angle is.
This is the code that gets called each time the image needs to be updated, after the appropriate glRotatef calls.
GLuint texName[1];
GLUquadricObj *gobj=gluNewQuadric();
gluQuadricDrawStyle(gobj,GLU_FILL);
gluQuadricNormals(gobj,GLU_SMOOTH);
gluQuadricTexture(gobj,GL_TRUE);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(MATERIALCOUNT,texName);
glBindTexture(GL_TEXTURE_2D,texName[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,TEXTURE_WIDE,TEXTURE_HIGH,
0,GL_RGB,GL_UNSIGNED_BYTE,TextureData);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glBindTexture(GL_TEXTURE_2D,texName[0]);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
gluSphere(gobj,0.75f,32,32);
glFinish();
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
glDisable(GL_CULL_FACE);
gluDeleteQuadric(gobj);
glDeleteTextures(1,texName);
I’m sure I’m missing something pretty obvious, but I can’t see it. I’ll be eternally grateful 'til next Tuesday if someone can point out what I’m doing wrong.
Thanks.
-Walt