Masking textures with other textures

Hi!

I’m trying to make a transition between two tiles on a terrain. Currently I have a separate texture for every transistion combination, but that’s a lot of textures!

I thought I could do something like this:

Have a black and white (or whatever) texture with the transistion shape in it.

Draw that on the tile, then draw the tile again, putting one texture where white has been drawn, and the other where black has been drawn.

I thought there would be some cunning arrangment of BlendFuncs and TexEnvs to do this, but I can’t work one out…

Any ideas?

Thanks in advance,

Nick

You can do this with multitexturing (if your system support it, it’s an extension).

There is also another way to do this in two renderingpasses. You can draw the polygon one time with one texture, with all alpha values set to 1.0. Either disable depthdest, or set depthfunction to GL_ALWAYS. Then draw same polygon again, but now with the second texture and alpha values set to: 1.0 for the corners where you want the second texture to be fully drawn, and 0.0 for the corners where you dont want the texture to be drawn at all.

Something like this:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// activate texture 1
glColor4f(1, 1, 1, 1);
glTexCoord2f(0, 0);
glVertex3f(0, 0);
glTexCoord2f(1, 0);
glVertex3f(1, 0);
glTexCoord2f(1, 1);
glVertex3f(1, 1);
glTexCoord2f(0, 1);
glVertex3f(0, 1);

// deactivate dephtbuffertest
// activate texture 2
glColor4f(1, 1, 1, 1);
glTexCoord2f(0, 0);
glVertex3f(0, 0);
glTexCoord2f(1, 0);
glVertex3f(1, 0);
glColor4f(1, 1, 1, 0);
glTexCoord2f(1, 1);
glVertex3f(1, 1);
glTexCoord2f(0, 1);
glVertex3f(0, 1);

Not really sure this is the right blendfunction.

This code (should) smoothly go from one texture to another, there’s no direct “jump” at a certain point.

For 2-pass method you can draw first pass as usual (Z-test&write),
and 2nd - with Z-write disabled, Z-test : GL_EQUAL