Original Post
I'm having some difficulty with blending textures, I'm trying to draw color textures on white areas of mask textures. Both parts look ok when rendered separately (fig1 and fig2), but when rendered together the two color textures are mixed on eachother (fig3) rather then seperated (fig4). I've been reading and trying some diffrent approaches without any luck, can someone advise what the correct steps are I need to take in order to get a result as on fig4? (without an extension)
// background ********************************
glPushMatrix();
glLoadIdentity();
gluLookAt( 5.5f, 7.5f, -5.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f );
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE); // or: glBlendFunc (GL_SRC_ALPHA, GL_ONE); glColor4f(1.0f,1.0f,1.0f,1.0f);
// draw mask texture
glBindTexture(GL_TEXTURE_2D, TEXID_MAP_MIXMAP_NOISE);
msh_map_large_uv_untiled.render_VT();
glBlendFunc(GL_DST_COLOR, GL_ZERO);
// draw foreground texture
glBindTexture(GL_TEXTURE_2D, TEXID_MAP_GRASS_BACKGROUND);
msh_map_large_uv_tiled.render_VT();
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glPopMatrix();
// foreground ********************************
glPushMatrix();
glLoadIdentity();
gluLookAt( 5.5f, 7.5f, -5.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f );
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE); // or: glBlendFunc (GL_SRC_ALPHA, GL_ONE); glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
// draw mask texture(inverted)
glBindTexture(GL_TEXTURE_2D, TEXID_MAP_MIXMAP_NOISE_INVERTED);
msh_map_large_uv_untiled.render_VT();
glBlendFunc(GL_DST_COLOR, GL_ZERO);
// draw foreground texture
glBindTexture(GL_TEXTURE_2D, TEXID_MAP_GRASS_FOREGROUND);
msh_map_large_uv_tiled.render_VT();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glPopMatrix();