views:

1355

answers:

1

This maybe a noob question, however, I haven't been able to find a suitable answers:

I have an object in OpenGL ES (in fact, an UV mapped export from Blender) and I'd like to apply two textures to it. To be precise, I have a earth-like sphere and I would like to add two textures (a day-side and a night-side) to it.

I had thought through alpha mapping, it should be possible to programmatically fade one texture and display the other during run-time so that my globe becomes a realistic simulation of the earth. I have the math behind it, i.e. creating the alpha-map for each face of the object is not the problem.

Any hints/pointers how this can be achieved?

Thanks

+2  A: 

The effect you’re looking for can be achieved with texture combiners in OpenGL ES 1.1. By default, each texture unit that you enable is set up to multiply the output of the previous stage by the color of the current texture. In the case of the first texture unit, the previous stage is simply the vertex color. By changing the texture combiner state, you can add, subtract, interpolate, or take dot products of your texture samples instead.

The second and third examples on the linked page, which interpolate between two textures, should be fairly similar to what you’re trying to do. If you compare the source code for the two examples, you should see that they’re nearly identical, except for the configuration for GL_SRC2_RGB/GL_SRC2_ALPHA and GL_OPERAND2_RGB/GL_OPERAND2_ALPHA. What’ll you'll need to specify here depends on where/how you’re generating the blend factor for the two textures. You can source from the vertex color by specifying GL_PRIMARY_COLOR for GL_SRC2_*, which isn’t shown in the examples.

(Note: the page I linked to recommends using GLSL instead of texture combiners. This is unfortunately not an option if your software needs to run on older hardware that doesn’t support OpenGL ES 2.0.)

Pivot