Basic OpenGL lighting question
I think this is an extremely stupid and newbie question, but then I am a newbie in graphics and openGL. Having drawn a sphere an开发者_如何学Pythond put a light source nearby, also having specified ambient light, I started experimenting with light and material values and came to a surprising conclusion: the colors which we specify with glColor*
do not matter at all when lighting is enabled. Instead, the equivalent is the material's ambient component. Is this conclusion correct? Thanks
If the lighting is enabled, then instead of the vertex color, the material color (well, colors - there are several of them for different types of response to light) is used. Material colors are specified by glMaterial*
functions.
If you want to reuse your code, you can use glEnable(GL_COLOR_MATERIAL)
and glColorMaterial(GL_AMBIENT_AND_DIFFUSE)
to have your old glColor*
calls mapped to material color automatically.
(And please switch to shaders as fast as possible - the shader approach is both easier and more powerful)
I suppose you don't use fragment shader yet. From glprogramming.com:
vertex color = the material emission at that vertex + the global ambient light scaled by the materials ambient property at that vertex + the ambient, diffuse, and specular contributions from all the light sources, properly attenuated
So yes, vertex color is not used.
Edit: You can also look for GL lightning equation in GL specification (you have one nearby, do you? ^^)
精彩评论