PDA

View Full Version : Put texture on a sphere



Nrtesn Nyarlahotep
02-28-2008, 03:01 AM
Hi!

This is what I'm trying to do: Put textures on a sphere so it looks nice. I've drawn some nice eyes I want to try out :)

The closest I've come to a solution is this implementation of shpere-mapping (textureId is loaded with a texture):

glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, textureId);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

glutSolidSphere(1,50,50);

glDisable(GL_TEXTURE_2D);

It looks nice but since it's sphere-mapped the textures doesn't rotate along with the sphere. I admit I'm new to OpenGl but I realise it's not sphere-mapping I want.

However sphere-mapping was the most related concept I could google for and I hoped I could work from there.

I've looked up those functions but it doesn't look like they can be used to do what I want, or am I missing something?

I'm just wondering if there is a nice way to put textures onto a sphere? The only other way I can think of is doing something cool with GLSL, but I enjoy simple solutions when they exist.

Any help would be very aprichiated. Thanks! :)

ProsperLOADED
02-28-2008, 08:29 AM
Actually, you don't need to generate texture coords since you're using glutSolidSphere. The glutSolidSphere function already provides correct texture coordinates for the sphere.

Nrtesn Nyarlahotep
03-01-2008, 10:42 AM
Thank you for your reply, but you don't mean gluSphere? I searched a little more and the gluSphere have an additional argument to turn on textures.

Or does GlutSolidSphere have texture-coordniates as well? How are they positioned? I couldn't find anything about it here on this site.

If anyone's interested it worked with the textures on gluSphere, but I had to draw the eye like a world map where the poles cover almost the entire top and bottom. The pupil had to be a thine line at the bottom and so on.

The code to implement it looks like this:

GLUquadric *qobj = gluNewQuadric();

gluQuadricTexture(qobj,GL_TRUE);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textureId);

gluSphere(qobj,1,50,50);

gluDeleteQuadric(qobj);
glDisable(GL_TEXTURE_2D);

Zengar
03-01-2008, 11:23 AM
You asked about glutSolidSphere, not gluSphere. This are different functions from different libraries. AFAIK, glutSolidSphere automatically supplies texture coordinates; just as PsosperLOADED said.

If you need a special kind of mapping, try generating the sphere yourself. Or model it with a 3d modeller.