PDA

View Full Version : multiple texturing



hong c.
03-10-2009, 08:05 PM
I'm writing a basic planet viewer OpenGL 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")?

The earth texture is a color image and the cloud texture is a grey-level image. I want the final result to be like cloud floating above the earth.

I tried use different texture environment, but the earth texture is always hidden by the cloud. Which environment parameter should I choose?

hong c.
03-10-2009, 08:07 PM
Specifically, How should I setup your glTexEnvf calls?

scratt
03-10-2009, 08:30 PM
I am not sure if gluSphere supports multi-texturing. I rolled my own sphere code, and use shaders for multi-texturing.

But basically for the FF pipeline this is what you need to do..

glEnable(GL_TEXTURE_2D);

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

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

I would put GL_REPLACE in the first TexEnv and GL_BLEND in the second and see how it looked, and then go from there..
The options are fairly well documented here...
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/texenv.html

Here's a useful page on some ways of combining textures..
http://www.opengl.org/wiki/Texture_Combiners
An example in GLSL is underneath the FF pipeline commands, which might tempt you to look into shaders.. :)

Alternatively send two spheres, the second slightly larger than the first, and have the clouds on the second one.

In the end this is how I do my clouds as I then have some parallax between the clouds and the ground, and can blend cloud shadows onto the 'earthtex' sphere...

hong c.
03-12-2009, 09:08 AM
Thank you. Very helpful.

pjcozzi
03-12-2009, 02:38 PM
Also, if you happen to have a copy of the orange book (http://www.3dshaders.com/home/), chapter 10 has some great examples of using multitexturing for rendering the earth: night lights on the dark side of the globe, gloss maps for the ocean, etc. Their examples use shaders but are still straightforward.

Patrick

hong c.
03-12-2009, 08:58 PM
Alternatively send two spheres, the second slightly larger than the first, and have the clouds on the second one.



I tried this approach but did not succeed. I am very new to OPenGL. If I set the second sphere translucent, it seems to me the first sphere is not shown, while the back sides of the second sphere shows when the sphere rotates.

Should I use the some culling method to get ride of the back side when the ball is rotating? Is there any there easy implementation that solves the problem? Or can you give more details on your approach of using two spheres? Thank you.