View Full Version : GL_LIGHTING kills blending operations with glColor?

07-18-2005, 01:44 PM
Blending is working fine until I enable lighting. It looks like glLightfv takes a 4 dimensional vector which overrides glColor*fv, so my vertex alpha values aren't getting through. Is that right? How do you blend across vertices while using lighting?

07-18-2005, 06:30 PM
Lighting doesn't kill blending. What it does is write to the vertex colour, overwriting anything that was already there. Off the top of my head, there are a few ways to get around this: materials, textures, vertex shaders, multi-passing. . .

07-18-2005, 07:14 PM
Thanks for responding. It must be materials that I'm after then. I'll have to read more about lighting to understand materials and glColorMaterials.

I think ideally, the color resulting from lighting would be multiplied times the existing values in glColor. Is there a function like that in materials?

07-18-2005, 07:29 PM
That's basically what materials do. Specifically, the value from the colour (which lighting writes to) is multiplied by the material colour. The only problem is that materials are not specified on a per-vertex basis. Instead, materials affect an entire draw call.

07-18-2005, 08:43 PM
I haven't had a chance to code anything but I thought the purpose of glColorMaterials was going to be to allow the material color to be set per-vertex with glColor while lighting is enabled.

07-18-2005, 09:46 PM
Ah! My appologies. . . I must admit that I've never had to use materials and largely skipped standard lighting. I went right into vertex and fragment shaders as soon as I could. :)

Anyway, if GL_COLOR_MATERIAL is enabled, the material colour will be the vertices' colour and the lighting will by multiplied with it. This is described in section 2.14.3 of the OpenGL spec.