texture mapping of two planes

I have two planes set at different depths apart. I would like to make the front plane look transparent so that the texture of back plane can be seen through. Could any one suggest how can that be done? Thanks in advance.

Look for ‘blending’ (glBlendFunc, enable blending etc) and don’t forget to render from back to front.

Hi,i am still getting difficulty. Could you give me some simple example, two planes textured and set at different depths apart. I would like to make the first plane transparent so that the second plane can been seen through. I am not getting any full example so that I can run it and understand it before I apply on my own work. Again thanks in advance.

glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE); // or other parameters, depending whether you have alpha in your texture (or set it via fragment shader) and what exactly you want

drawPlane1(); // back
drawPlane2(); // front

If you have specific questions, maybe some of your code will help us to understand it.

Hi, my coding is as follows. I see nothing just white background.
/**************************************************************/

initPlanes(){

TextureLoader *pTextureLoader = new TextureLoader();
glTexture m_MyLogoTexture;
TextureLoader *pTextureLoaderOne = new TextureLoader();
glTexture m_MyLogoTextureOne;

pTextureLoader->SetHighQualityTextures(TRUE);
pTextureLoader->SetMipMapping(TRUE);
pTextureLoader->SetTextureFilter(txTrilinear);
pTextureLoader->LoadTextureFromDisk(“models/human_anterior_back.JPG”, &m_MyLogoTexture);
pTextureLoaderOne->SetHighQualityTextures(TRUE);
pTextureLoaderOne->SetMipMapping(TRUE);
pTextureLoaderOne->SetTextureFilter(txTrilinear);
pTextureLoaderOne->LoadTextureFromDisk(“models/human_anterior_front.JPG”, &m_MyLogoTextureOne);

}

drawBackPlane(){

glEnable( GL_TEXTURE_2D );
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_COLOR_MATERIAL);
glBindTexture( GL_TEXTURE_2D, m_MyLogoTexture.TextureID );

glBegin( GL_QUADS ); //back plane
glTexCoord2d(0.0, 0.0); glVertex3d( -6.0,-4.0, 0.0);
glTexCoord2d(0.25, 0.0); glVertex3d( 6.0, -4.0, 0.0);
glTexCoord2d(0.25, 1.0); glVertex3d( 6.0, 4.0, 0.0);
glTexCoord2d(0.0, 1.0); glVertex3d( -6.0, 4.0, 0.0);
glEnd();

glFlush();
glDisable( GL_TEXTURE_2D );

}

drawFrontPlane(){

glEnable( GL_TEXTURE_2D );
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_COLOR_MATERIAL);
glBindTexture( GL_TEXTURE_2D, m_MyLogoTextureOne.TextureID );

glBegin(GL_QUADS ); //frontplane
glTexCoord2d(0.0, 0.0); glVertex3d( -6.0,-4.0, 1.5);
glTexCoord2d(0.25, 0.0); glVertex3d( 6.0, -4.0, 1.5);
glTexCoord2d(0.25, 1.0); glVertex3d( 6.0, 4.0, 1.5);
glTexCoord2d(0.0, 1.0); glVertex3d( -6.0, 4.0, 1.5);
glEnd();

glFlush();
glDisable( GL_TEXTURE_2D );

}

drawPlanes(){

glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);

drawPlaneBack();
drawPlaneFront();

}

/*********************************************/

I don’t know about fragment shader. My texture loader constructor is as follows:

TextureLoader::TextureLoader()
{
// default to alpha matching BLACK
SetAlphaMatch(TRUE, 0, 0, 0); // Set the Alpha Matching State

// default to full sized textures
SetHighQualityTextures(TRUE);

// no mipmap textures
SetMipMapping(FALSE);

// no texture filtering
SetTextureFilter(txNoFilter);

}

Do you see the front plane if rendered without blending?
Is your clear color white?
WHere does your camera look at?
Is the scene within the view frustum?

Yes, everthing is ok without blending. clear color is white. The scene is within viewing frustum. I hv never used blending before, it is difficult to understand what the problem is.

With glBlendFunc (GL_ONE, GL_ONE); you will only add colors, meaning white will stay white.
Try instead glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for a more classic blending.
Some visual examples here : http://www.machwerx.com/2009/02/11/glblendfunc/
And a simulator here to play with settings : http://www.andersriggelsen.dk/glblendfunc.php

Then of course it will depend of the alpha defined in your textures.

A last trap is that depth testing does not work well with blending, so be sure to draw the back plane before the front plane. If the camera moves it may be needed to change to drawing order dynamically.

Thank u all for contribution. But still I could not manage to make it work properly. With “glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)”, I don’t see white like before, but I see the image in the same condition as it seems without having any blending. I think the problem may be with alpha manipulation. In my texture loader program by default:

// default to alpha matching BLACK
SetAlphaMatch(TRUE, 0.0, 0.0, 0.0);

Suppose I loaded two textures, one for front plane and the other for back plane. I have changed the above mentioned function as follows for front as well as back plane:

SetAlphaMatch(TRUE, 0.5, 0.5, 0.5);

But still don’t notice any change.

I need help to figure out my problem.

Hi All, I have been able to get some output using the following:

glEnable(GL_BLEND);
glBlendFunc( GL_SRC_COLOR, GL_DST_COLOR);

Other options with glBlendFunc did not work with me. I have given the back plane a colored background, otherwise I could not get the outline of the front plane. It would be good if some one explains this. I have uploaded the result to the following url:

http://www.crocko.com/D8F8A53405024FCDAE0162B9569A1209/Figure.doc

I have made front plane deformable. When front plane touches the back plane, some different color is created which I don’t want. Could any one suggest, how can I get rid of this noise?

Thanks every body in advance for all of your valuable suggestions.

Ah so your image have no proper alpha ?
This is a problem you have to fix, and keep the blendfunc to the one I proposed.
Maybe just doing glColor4f(1.0,1.0,1.0,0.5) to make stuff uniformly half-transparent.

Can you show does this do exactly :
SetAlphaMatch(TRUE, 0.1, 0.1, 0.1);

Is that an exact match ? Or that any texel darker than this will be transparent ?

Hi, I hv used the following:

glColor4f(1.0,1.0,1.0,0.5);
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

It works, but looks a bit dark. I could not manage to work with the following function:
SetAlphaMatch(TRUE, 0.1, 0.1, 0.1);

I think it is supposed to control the alpha of a particular texture.

As my first plane deforms and penetrates the second plane, there appears another blending. I don’t want it happen. How can that be done?

OpenGL Blending is order-dependent.
Be sure to draw back to front, otherwise it does not work. The depth buffer works only for opaque rendering, translucent surfaces need more complex structures, search for “order-independent transparency”.

It seems you are at a dead-end, can you explain the high level concept being your needs, maybe there are better solutions ?

Actually now what I want is:
when the front plane is pressed and crosses the back plane, the colored box will not appear. Can that be done? What would be condition for this kind of blending?

Hello, I have some simple questions about texture. How can I understand whether my texture has alpha value or not? How can I separate color of a texture for different points as I need to differentiate white portion of the texture from other portions? Questions may be too simple but I really do need to clarify these things.

How can I understand whether my texture has alpha value or not?

You gave the texture data to OpenGL, didn’t you? You told OpenGL what image format to use, yes? If you don’t ask for alpha, you don’t get alpha.

Ok, I understand. I need to add alpha to have some transparency effect. But how can I separate RGB values of a certain point of texture?