views:

1209

answers:

3

I'm writing a basic planet viewer OpenGL Perl application, just for fun. I have the basics working, with the glorious planet, implemented through a gluSphere(), rotating with the classic earth texture map applied.

Now, what if I want to apply a second texture map through OpenGL (say, the "earth clouds")?

Of course, I can mix the two texture maps myself in PhotoShop or some other graphic application, but is there a way through OpenGL API?

I tried loading the two textures and generating the mipmaps but the planet is shown with only the first texture applied, not the second.

+5  A: 

How do you want your textures to be combined? You should be able to get your desired effect if you simply use multi-texturing:

glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture0ID);
glTexEnvf(GL_TEXTURE_ENV, ..., ...);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture1ID);
glTexEnvf(GL_TEXTURE_ENV, ..., ...);

Be sure to setup your glTexEnvf calls depending on how you want the textures to be combined. Then call gluSphere().

Jim Buck
+4  A: 

As Jim Buck said, you can get the desired effect with multitexturing.

However, I don't think the GLU quadrics support multitexture coordinate generation (i.e. using glMultiTexCoord*() vs. glTexCoord*(). So, I think you'll need your own sphere code to go the multitexture route.

Alternatively, you might be able to get away with drawing a slightly bigger sphere around your current one that has the second texture map on it (with appropriate use of the alpha channel & blending). This is likely to cause z-fighting though, so it may be more trouble than it's worth.

Writing your own sphere code isn't hard--probably the easiest route to get satisfactory results.

Drew Hall
A: 

I agree with Drew Hall. Maybe simpler to make a second sphere. And not all opengl cards support multi-texturing.

You can counter z-fighting with glPolygonOffset.

Kalle