November 10, 2010, 5:39pm
I want an object of my scene to become gradually translucent, when an event occurs, and then get back gradually again to opaque.
My blending funcion is:
When the event occurs, the translucent object is rendered as:
glColor4f(1.0f, 1.0f, 1.0f, alphaCounter);
The effect itself works fine, but I have this problem. In the beginning and end of the effect, since lighting must be disabled for blending, the object I test looks for a moment brighter. This make sense since when lighting is enabled, this object should be darker at the position I placed it, but when lighting is disabled it is rendered only according to the glColor4f values.
Is there any way to have lighting enabled when blending? Or is there any other workaround for my problem?
November 11, 2010, 2:00am
I thought that this was the case, at least when using this blend function. And when I do have lighting enabled, blending does not work at all.
November 11, 2010, 5:42am
Then you are doing some else wrong.
November 11, 2010, 8:44am
Yes, but what might that be… Even if I put only this simple code in my render function,
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.1f, 0.5f, 0.9f, 1.0f);
Rectangle r1 = new Rectangle(1.0f, 1.0f, 1.0f);
Rectangle r2 = new Rectangle(1.0f, 1.0f, 1.0f);
glTranslatef(0.0f, 0.0f, -1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glTranslatef(0.5f, 0.0f, 0.0f);
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
the translucency appears only when lighting is disabled. Any ideas?
fixed function lighting uses material properties, set with glMaterial(). In order for the vertex colors (set by glColor4f, etc) to affect lighting you need a call to glColorMaterial().
Right. And don’t forget to glEnable( GL_COLOR_MATERIAL ) to enable the color->material behavior you select with glColorMaterial.
November 11, 2010, 3:04pm
Thanks! I will try to use materials.