Archived

This topic is now archived and is closed to further replies.

Kiroke

how do we rotate texture with sphere??

Recommended Posts

Kiroke    122
hi! well...the subject is pretty self explanatory. I wanted to know to i can turn the texture that is around a sphere using glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); The sphere is rotating but not the texture thx

Share this post


Link to post
Share on other sites
vincoof    514
You may not be using the right texture generation equations.

You''re using texture generation (because you enabled GL_TEXTURE_GEN_S/T) but you also have to tell OpenGL how he have to compute the coordinates.

Use glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); to compute the coordinates relatively to the object. (Do the same with replacing the first paramater as GL_T).

Then use glTexGenfv( GL_S, GL_OBJECT_PLANE, equation_s ); to set the equation for the S texture coordinate, where equation_s is an array of 4 floats defining how to compute the texture coordinate from vertex coordinate. (Again, do the same with GL_S replaced by GL_T, but with another equation ).

The thing is, that comes very handy with plane objects, so you''ll have weird results on your sphere.
this is because the texture generation is GL_OBJECT_LINEAR.
You can have other params, but they are worse :
- GL_EYE_LINEAR computes the texture coordinates relatively to the Eye (the centre of the camera) which gives results like the one you described,
- GL_SPHERE_MAP generates environment mapping, which is very cool but does not help you in your case.

The fact is, you can not generate texture coordinates that "moves with the sphere" from automatic texture generation equation.
In fact, you have to use the functions like glTexCoord2f which defines the texture coordinates vertex per vertex. sorry

Share this post


Link to post
Share on other sites
vincoof    514
That''s right, but it needs the GLU.
Well, almost everyone uses it...

Lookin for high-level libraries, the GLUT and GLAUX also do that, and even easier.

Share this post


Link to post
Share on other sites