Texture a sphere with glTexGen

Hi. I am trying to do something that is probably brain-dead simple, but not working for me. I am trying to texture a basic sphere. I am using wxWidgets, so I believe I cannot use the glut tools (or is difficult to set the two up simultaneously).

I am using glTexParameter*, glTexGen*, glTexImage*, and gluSphere. I am using a texture that is 128x128 pix. I have been using the OpenGL Red Book and searching the web extensively, but I cannot find the help I need. I’ll describe the problem here and paste the code below.

The texture gets applied to my sphere. If I use the GL_SPHERE_MAP with glTexGen, the rendering of the image on the sphere is precisely what I want… but of course, the image is not attached to the sphere… so when the sphere spins, the texture stays in one spot… my texture is not a reflection so this is not what I want. So I switched to using GL_OBJECT_LINEAR with glTexGen, and now the image is attached to the object… BUT, it is pasted on the object in eight sections. That is to say if you chopped up an orange through the center once with the X plane, once with the Y plane, and once with the Z plane, you’d get eight pieces. For each peel of the orange, there is one of my textures, unlike when I used the GL_SPHERE_MAP where the one image was covering one complete half of the sphere.

I guess what I want is the image to look like it does with GL_SPHERE_MAP, but be attached to the object as it is with GL_OBJECT_LINEAR.

Thanks for your help!

Here is the code snippet:

  
static GLUquadricObj *quadratic;

void init()
{
...
quadratic = gluNewQuadric();
gluQuadricNormals( quadratic, GLU_SMOOTH );
gluQuadricTexture( quadratic, GL_TRUE );
glBindTexture( GL_TEXTURE_2D, texName );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imageData.GetImageWidth(), imageData.GetImageHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, imageData.GetPixels() );
...
}

void draw()
{
...
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
gluSphere( quadratic, 1.0f, 20, 20);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
...
}

I’m nor really sure what kind of effect you are going for. But one possibility is to generate both the sphere and its texture coordinates yourself, using the same math that OpenGL does for the generation method you like. The functions that OpenGL uses can be found in the specification (currently version 2.1).

http://www.opengl.org/documentation/specs/

I think you’ll find in the long run it’s better to create your own stuff, so that you can freely manipulate it. This is create once, use forever kind of stuff, so it’s really worth the small initial effort, especially for the likes of spheres, cubes and cylinders.

If you are interested in reflection mapping, you may want to look into cubemaps.

Thanks for the tip, flavious. I was thinking about creating my own tex coords. I think I’ll give that a shot.

Hi

No too sure what yu want to do, but, I noticed you left out :

gluQuadricDrawStyle (quadratic, GLU_FILL) ;

…Might want to add some lighting, too.

…maybe, put it all in a display list, in your init() and define SPHERE 1 up´in your global header area, perhaps.

see ya

Refrigerator