The main issue of OpenGL lighting

I think this is a very stupid and newbie question, but then I am new to graphics and openGL. I drew a sphere and placed the light source next to it, also indicating the surrounding light, I began to experiment with light and material values ​​and came to an unexpected conclusion: the colors that we use with glColor* do not matter at all when the lights are turned on. Instead, the equivalent is component of the environment. Is this conclusion correct? Thanks

+4
source share
2 answers

If the lighting is on, then instead of the color of the vertices, the color of the material (well, colors - there are several of them for different types of response to light). The color of the material is set by the glMaterial* functions.

If you want to reuse your code, you can use glEnable(GL_COLOR_MATERIAL) and glColorMaterial(GL_AMBIENT_AND_DIFFUSE) so that your old glColor* calls appear automatically in the material color.

(And please switch to shaders as soon as possible - the shader approach will become simpler and more powerful)

+5
source

I assume you are not using a flash 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 search for the GL lightning equation in the GL spec (you have one nearby, are you? ^^)

+3
source

All Articles