4

I think this is an extremely stupid and newbie question, but then I am a newbie in graphics and openGL. Having drawn a sphere and 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

Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434

2 Answers2

5

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)

Kos
  • 70,399
  • 25
  • 169
  • 233
  • I have heard so much about these shaders, but I have no idea what they are. I guess I'll just have to be patient till I get to the relevant chapters of the Redbook :) Thanks for the answer – Armen Tsirunyan Nov 13 '10 at 13:38
  • The Redbook is as outdated as the whole fixed function rendering which we're discussing. You can read it for some theory and that's it. For shader tutorials, google for Lighthouse3D. :) Also have a glance on OpenGL 2.1 or OpenGL 3 reference docs on opengl.org/documentation/specs/ - they are somewhat big, but a skim will give you a good idea how OGL works. – Kos Nov 13 '10 at 13:52
  • @Kos: If the redbook is outdated, what book would you recommend? A documentation is not a book, it's a good thing, but beginners find it hard to use the documentation directly – Armen Tsirunyan Nov 13 '10 at 15:49
  • Learning directly from the documentation is definitely a required skill in every programmer's skill tree, but I agree that the tutorials or books make it easier for beginners to start because they shorten the time between starting to learn and seeing *something which works*, which is kind of important. However, it's equally important to keep the doc under the pillow and *try* to use it for answering one's questions. I cannot recommend any book, but I sincerely believe that Lighthouse 3D tutorials (or others available online) should be sufficient for apprentice OpenGL-ists. – Kos Nov 13 '10 at 16:19
  • @Armen: Which version of the Redbook do you have in your possession? – elmattic Nov 14 '10 at 13:56
  • @Armen: I agree with Kos, please switch to GLSL shaders. Because the FFP (fixed function pipeline) is so boring and outdated :) – elmattic Nov 14 '10 at 13:59
  • @Stringer Bell: I have the seventh edition : Versions 3.0 and 3.1 – Armen Tsirunyan Nov 14 '10 at 14:01
3

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? ^^)

Community
  • 1
  • 1
alxx
  • 9,897
  • 4
  • 26
  • 41