PDA

View Full Version : Multi-Texturing and Texture-Mapping!



Silver
04-11-2004, 09:03 AM
Hello!

I have written a C-Program under Linux, which should contain a ground with a texture on it, and a box which is multi-textured (with 2 textures)!
The problem is, that it doesn't show the ground. I guess, OpenGl thinks that the floor-texure is the third texture unit.

Here the texture-initialization code:

glBindTexture(GL_TEXTURE_2D, BOXTex->ID);
glTexParameteri(..);
gluBuild2DMipmaps(..);


glBindTexture(GL_TEXTURE_2D, BOX2Tex->ID);
glTexParameteri(..);
gluBuild2DMipmaps(...);

glBindTexture(GL_TEXTURE_2D, FLOORTex->ID);
glTexParameteri(..);
gluBuild2DMipmaps(..);


glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, BOXTex->ID); // bind to TU 0

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, BOX2Tex->ID); // bind to TU 1
But the FLOOR-texture is always drawn on the box, although i passed the right positions of the vertices.

hyh!

plasmonster
04-11-2004, 09:36 AM
Whenever multi-texturing is involved, you must specify how the texture units are to be combined to produce a result. Think of the texture units collectively as a giant blender, feed it some textures, and hit the puree button. The default mode of operation for combining is GL_MODULATE. This means that the result of a texturing operation is: color = texUnit0 * texUnit1, where the multiplication is a component by component product, and texUnit(0,1...n) is the output of each unit. If you want a different behavior, you can specify it with
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode );
where mode is one of GL_MODULATE, GL_REPLACE, .., and so on. There are quite a few.
The idea is that OpenGL has no idea how you want to combine texture units, so you must supply that info. Keep in mind that each texture unit has its own combiner, so you need to activate the desired unit with glActiveTextureARB(num),
and the set the combiner mode. The OpenGL programming guide covers this area at length, if you would like the full monty.