Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to anchor the texture on a sphere

Started by alin_oana Nov 8, 2007 at 4:48 PM 3 replies 6.6k views
Original Post
alin_oana
alin_oana
Hi! I am drawing a solid sphere using glutSolidSphere(,,). On this sphere 'm mapping a texture . glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable( GL_TEXTURE_2D ); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, texture[0]); glColor3f(1,1,1); glutSolidSphere(dim,32,32); The problem is that when I'm rotating the sphere, I always see the same image (the tezture image is not rotating with the sphere). What shell I do in order to get read of this effect. Thank you!
Daaark
Daaark
Sphere mapping is not for mapping onto a sphere mesh, it's to use spherical coordinates with any kind of mesh, so that the texture layer with the sphere map always has the center of the texture facing towards the camera, and as the surfaces turn away fro the camera, the part of the texture they have on them moves outward (hard to explain).

You can use it to make nice fake highlights on shiny objects. It's not made to auto texture a sphere.

Here is an example,
http://www.cs.unc.edu/~hoff/projects/summer98_disney_lighting_effects/docs/phonghighlight/index.html
trouble2007
trouble2007
Hi,
I had that problem but fixed it by having

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glBindTexture (GL_TEXTURE_2D, tex);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

The sphere rotates and everythign rotates fine, but the image(earth texture) is mapped several times instead of being stretched on the whole sphere. Any help would e greatly appreciated.
Thanks!
SirKnight
SirKnight
Quote:
Original post by trouble2007
Hi,
I had that problem but fixed it by having

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glBindTexture (GL_TEXTURE_2D, tex);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

The sphere rotates and everythign rotates fine, but the image(earth texture) is mapped several times instead of being stretched on the whole sphere. Any help would e greatly appreciated.
Thanks!


Use glTexParameteri with GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T.
trouble2007
trouble2007
Quote:
Original post by SirKnight
Quote:
Original post by trouble2007
Hi,
I had that problem but fixed it by having

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glBindTexture (GL_TEXTURE_2D, tex);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

The sphere rotates and everythign rotates fine, but the image(earth texture) is mapped several times instead of being stretched on the whole sphere. Any help would e greatly appreciated.
Thanks!


Use glTexParameteri with GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T.


Thanks for the quick reply, but i already had those defined so i guess something else might be the problem, any idea on what that may be?

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.