PDA

View Full Version : sphere texture problem



robert
02-21-2001, 11:54 PM
I have a small gluSphere (textured), when I move my scene around, the texture keeps getting re-aligned to face me (ie it moves). How can I stop this?

Also, Im not using
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

can someone tell be the difference between using these and not? Im not, and it works fine??

Nutty
02-22-2001, 04:44 AM
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
Just tells OpenGL how to calculate the texture coords IF auto texture coord generation is turned on.

To turn it on use glEnable(GL_TEXTURE_GEN_S);
and glEnable(GL_TEXTURE_GEN_T);

Make sure you have these disabled. Use the appropriate tokens to glDisable.

Never used those glu functions so I'm not sure what else the problem could be.

heck
02-22-2001, 02:15 PM
Lets look, maybe i an help (I've done a Texturing class yesterday)
First, I load my Textures like this :

glBindTexture(GL_TEXTURE_2D, Texture); 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_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3,
Image->sizeX, Image->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, Image->data);

Where Image is AUX_RGBImageRec.
I dont think the bug is int this part. But So far just assure, we are loading the texture the same way.

Now here's the important part:

in your RenderScene method, before glBegin(); and glEnd(); put this:
glTexGenf(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_NV);
glTexGenf(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_NV);

for Reflection-mapping or this:

glTexGenf(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGenf(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);

for sphere-mapping.

NOW, it is URGENT, that you enable the automatic TexCoords generation:

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

And then if your code contains #include <gl/glut.h> put

glutSolidTeapot(double size);

after all that (erverything still in the RenderScene-method, of course)

and you should get a sphere- or reflection- mapped teapot.

easy tough... http://www.opengl.org/discussion_boards/ubb/smile.gif

Sorry for the layout (Mozilla nightly build is guilty , but FASTEST browser ever seen!!!)

robert
02-22-2001, 02:22 PM
cheers peoples, I'll try those out http://www.opengl.org/discussion_boards/ubb/smile.gif

I got it working without the auto coord geration, so now ill try and get it going with that http://www.opengl.org/discussion_boards/ubb/tongue.gif

robert
02-22-2001, 02:26 PM
Hey, when I use
glTexGenfGL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);
glTexGenfGL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP);


glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

and gluSphere()

The texture is drawn to always face me??

Bob
02-23-2001, 04:25 AM
Yepp, that's how sphere mapping works.

The texture you use is a reflectionmap of the environment, and GL_SPHERE_MAP calculates the proper texture coordinates so it appears that the object is reflecting the environment.