Sign in to follow this  

blending textures

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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();

mixmap.png

Share this post


Link to post
Share on other sites
You could use texture interolation. This has been core since GL 1.3

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureID2);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);

Share this post


Link to post
Share on other sites
NeHe lesson 22 would be good for this with the older OpenGL.
Bump-Mapping, Multi-Texturing & Extensions

Note the part which uses the alpha channel to 'professionally' blend the logos on screen. I used this technique with bezier handles and was pleasantly surprised with the results.

Also, the code gets the alpha 'bitmap' and copies just the 'red' channel to the 'alpha' channel of your bitmap. You could then save the texture if you want to be efficient.

Share this post


Link to post
Share on other sites
@V-man:
Thanks, I've looked into it and got multiple terrain textures displayed fine now.
(took me a while to figure out how all the diffrent glTexEnvi(GL_TEXTURE_ENV, ...) arguments do relate to eachother)

@jezham:
I've seen the NeHe lessons, but couldn't work out a solution for my case.
Also I can't combine my alpha textures into my rgb textures, the have diffrent dimensions (I forgot to notice that).

Share this post


Link to post
Share on other sites

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this