PDA

View Full Version : Make objects slowly vanish using blending



Rodrigo Robles
10-15-2012, 09:24 AM
I plan to make objects slowly vanish when distancing from the camera. Theoretically I should use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), but it's not working in my context, so I should be missing something.

I'm working with textured objects, GL_MODULATE, and lights enabled.

The code follows:



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4F(1,1,1,alfa);
glEnable(GL_CULL_FACE);


glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, FSkinID[0]);
//starts drawing with gl_begin(GL_TRIANGLE_FAN)


The alfa values range from 0 to 1 according with camera distance.
This code results in a normal drawing with no blending.

Rodrigo Robles
10-16-2012, 10:22 AM
It should work this way, isn't it?

carsten neumann
10-16-2012, 11:10 AM
When lighting is enabled material parameters (set with glMaterial (http://www.opengl.org/sdk/docs/man/xhtml/glMaterial.xml)) are used for calculations. Vertex colours are only considered if you set your material to track the current colour using glColorMaterial (http://www.opengl.org/sdk/docs/man/xhtml/glColorMaterial.xml).

Rodrigo Robles
10-16-2012, 01:31 PM
You're right! I just set the alpha value for the material and the blending worked like a charm! Thank you!