Hi!
I’m drawing a sphere and cover it with a texture.
That’s the problem: I want the texture to rotate with the sphere.
How can I do this?
Well, if you add the texture to the sphere, it would be attach to it.
Bind the texture before drawing the sphere
If you’re drawing a texture, you must have texture coordinates for your sphere vertices. So, when rotating the sphere, the texture will rotate too, unless you are not setting the texture coordinates correctly.
Sorry, but I don’t understand…I’m doing something like this:
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texture_id[1]);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTranslatef(posX, 1.0, posZ);
glutSolidSphere(palla.r, 12, 12);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glPopMatrix();
what kind of sphere vertex I’m suppose to consider?
I’m not sure, but I read somewhere that glutSolidSphere didn’t generate texture coordinates. Try glutSolidTeapot(), I’m sure that the teapot have texture coordinates.
Probably you are right.
But I need to draw a sphere not a teapot.
Anybody can help me, please?
You can use glu (gluSphere)
or you can use my library (glhCreateSpheref2 and example code is provided in the header).
Or as a fun exercise, create a sphere yourself.