Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I apply 2 or more texture maps to a gluSphere OpenGL object?

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.

like image 918
Cosimo Avatar asked Dec 18 '22 09:12

Cosimo


2 Answers

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().

like image 142
Jim Buck Avatar answered Feb 15 '23 11:02

Jim Buck


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.

like image 25
Drew Hall Avatar answered Feb 15 '23 11:02

Drew Hall